Add dagschotel to users

This commit is contained in:
Benjamin Cousaert 2014-12-09 20:28:50 +01:00
parent 465b9198ab
commit 9fe6bf7530
5 changed files with 15 additions and 2 deletions

View file

@ -16,6 +16,8 @@
# last_sign_in_at :datetime # last_sign_in_at :datetime
# current_sign_in_ip :string(255) # current_sign_in_ip :string(255)
# last_sign_in_ip :string(255) # last_sign_in_ip :string(255)
# dagschotel :reference
# dagschotel_id :integer
# #
class User < ActiveRecord::Base class User < ActiveRecord::Base
@ -23,11 +25,12 @@ class User < ActiveRecord::Base
:rememberable, :trackable :rememberable, :trackable
has_many :orders, -> { includes :products } has_many :orders, -> { includes :products }
belongs_to :dagschotel, class_name: 'Product'
validates :nickname, presence: true, uniqueness: true validates :nickname, presence: true, uniqueness: true
validates :name, presence: true validates :name, presence: true
validates :last_name, presence: true validates :last_name, presence: true
validates :password, length: { in: 8..128 }, confirmation: true validates :password, length: { in: 8..128 }, confirmation: true, on: :create
def full_name def full_name
"#{name} #{last_name}" "#{name} #{last_name}"

View file

@ -0,0 +1,5 @@
class AddDagschotelToUsers < ActiveRecord::Migration
def change
add_reference :users, :dagschotel
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141209172818) do ActiveRecord::Schema.define(version: 20141209192545) do
create_table "order_products", force: true do |t| create_table "order_products", force: true do |t|
t.integer "order_id" t.integer "order_id"
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20141209172818) do
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.integer "dagschotel_id"
end end
end end

View file

@ -16,6 +16,8 @@
# last_sign_in_at :datetime # last_sign_in_at :datetime
# current_sign_in_ip :string(255) # current_sign_in_ip :string(255)
# last_sign_in_ip :string(255) # last_sign_in_ip :string(255)
# dagschotel :reference
# dagschotel_id :integer
# #
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

View file

@ -16,6 +16,8 @@
# last_sign_in_at :datetime # last_sign_in_at :datetime
# current_sign_in_ip :string(255) # current_sign_in_ip :string(255)
# last_sign_in_ip :string(255) # last_sign_in_ip :string(255)
# dagschotel :reference
# dagschotel_id :integer
# #
require 'test_helper' require 'test_helper'