Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Forked from richardjortega/assocation.rb
Last active December 14, 2015 21:59
Show Gist options
  • Save tpendragon/5154999 to your computer and use it in GitHub Desktop.
Save tpendragon/5154999 to your computer and use it in GitHub Desktop.
## I need to have a Group that can consist of Users and/or Companies
class User
has_many :relationships
has_many :companies, :through => :relationships
has_many :groups, :as => :groupable
end
class Relationships
belongs_to :user
belongs_to :company
end
class Company
has_many :relationships
has_many :users, :through => :relationships
has_many :groups, :as => :groupable
end
class Membership
belongs_to :group
end
class Group
has_many :memberships
belongs_to :groupable, :polymorphic => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment