Skip to content

Instantly share code, notes, and snippets.

@brycemcd
Created May 19, 2011 19:25
Show Gist options
  • Save brycemcd/981513 to your computer and use it in GitHub Desktop.
Save brycemcd/981513 to your computer and use it in GitHub Desktop.
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