Skip to content

Instantly share code, notes, and snippets.

@Ross-Hunter
Created June 4, 2014 19:27
Show Gist options
  • Save Ross-Hunter/ea122684a5cbd1795083 to your computer and use it in GitHub Desktop.
Save Ross-Hunter/ea122684a5cbd1795083 to your computer and use it in GitHub Desktop.
##Class
class User
has_many :memberships
has_many :groups, through: :memberships
end
class Membership
belongs_to :user
belongs_to :group
end
class Group
has_many :memberships
end
##Migration
class CreateMemberships < ActiveRecord::Migration
def change
create_table :memberships, do |t|
t.references :user_id, index: true
t.references :group_id, index: true
t.timestamps
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment