Skip to content

Instantly share code, notes, and snippets.

@mfifth
Last active January 25, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mfifth/de154df87c618c9cda4b043e91d8c328 to your computer and use it in GitHub Desktop.
Save mfifth/de154df87c618c9cda4b043e91d8c328 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_many :groups, through: :group_users
end
class GroupUsers < ActiveRecord::Base
belongs_to :user
belongs_to :group
end
class Group < ActiveRecord::Base
has_many :users, through: :group_users
end
@kwerle
Copy link

kwerle commented Jan 25, 2017

class User < ActiveRecord::Base
  has_and_belongs_to_many :groups
  has_many :owned_groups, class_name: :Group
end

class Group < ActiveRecord::Base
  has_and_belongs_to_many :users
  belongs_to :owner, class_name: :User
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment