Created
May 19, 2011 19:25
-
-
Save brycemcd/981513 to your computer and use it in GitHub Desktop.
rails association help from http://stackoverflow.com/questions/6063537/rails-model-association-on-views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
has_many :groups | |
has_many :group_memberships, :foreign_key => "member_id", :through => :groups | |
scope :owned_groups, where(:is_owner => true).joins(:group_memberships) # gets all groups where this person is owner | |
end | |
class Group_Membership | |
belongs_to :member, :class_name => 'Person' | |
belongs_to :group | |
# note that these attributes need to be defined | |
# is_owner (boolean) | |
# member_approved (boolean) | |
scope :requested, :where(:member_approved => false) | |
end | |
class Group | |
belongs_to :person | |
has_many :group_memberships | |
has_many :members, :class_name => "Person", :through => "group_memberships", :foreign_key => "member_id" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment