Skip to content

Instantly share code, notes, and snippets.

@richardjortega
Created March 13, 2013 18:26
Show Gist options
  • Save richardjortega/5154784 to your computer and use it in GitHub Desktop.
Save richardjortega/5154784 to your computer and use it in GitHub Desktop.
testing multiple models through same has_many :through assocation
## I need to have a Group that can consist of Users and/or Companies
class User
has_many :relationships
has_many :companies, :through => :relationships
end
class Relationships
belongs_to :user
belongs_to :company
end
class Company
has_many :relationships
has_many :users, :through => :relationships
end
class Membership
belongs_to :company
belongs_to :user
belongs_to :group
end
class Group
has_many :memberships
has_many :users, :through => :memberships
has_many :companies, :through => :memberships
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment