app port from old version
This commit is contained in:
11
app/models/child.rb
Normal file
11
app/models/child.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class Child < ActiveRecord::Base
|
||||
has_many :parenthoods
|
||||
has_many :parents, through: :parenthoods, source: :person
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
4
app/models/parenthood.rb
Normal file
4
app/models/parenthood.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Parenthood < ActiveRecord::Base
|
||||
belongs_to :person
|
||||
belongs_to :child
|
||||
end
|
25
app/models/person.rb
Normal file
25
app/models/person.rb
Normal file
@ -0,0 +1,25 @@
|
||||
class Person < ActiveRecord::Base
|
||||
has_many :parenthoods
|
||||
has_many :children, through: :parenthoods
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
||||
scope :with_name, lambda { |name|
|
||||
where("concat(first_name, ' ', last_name) RLIKE ?", name)
|
||||
}
|
||||
|
||||
scope :just_parents, lambda {
|
||||
joins(:children)
|
||||
.order(:first_name)
|
||||
.uniq
|
||||
}
|
||||
|
||||
scope :staff, -> { where(staff: true) }
|
||||
|
||||
scope :admins, -> { where(admin: true) }
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user