Guest User

Untitled

a guest
Jul 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Person < ActiveRecord::Base
  2. has_many :parent_children
  3. has_many :children, :through => :parent_children
  4. has_many :parents, :through => :parent_children
  5.  
  6.  
  7. end
  8.  
  9. class ParentChild < ActiveRecord::Base
  10. belongs_to :parent, :class_name => "Person"
  11. belongs_to :child, :class_name => "Person"
  12. scope :mother, lambda {
  13. joins(:parent).where("parent.gender = 'F'")
  14. }
  15.  
  16. scope :father, lambda {
  17. joins(:parent).where("parent.gender ='M'")
  18. }
  19. end
Add Comment
Please, Sign In to add comment