Skip to content

Instantly share code, notes, and snippets.

@Ross-Hunter
Last active May 12, 2016 16:21
Show Gist options
  • Save Ross-Hunter/fc65bc87c1f57f34ed18 to your computer and use it in GitHub Desktop.
Save Ross-Hunter/fc65bc87c1f57f34ed18 to your computer and use it in GitHub Desktop.
##Class
class User
has_and_belongs_to_many :groups
end
class Group
has_and_belongs_to_many :groups
end
##Migration
class CreateUsersGroupsJoinTable < ActiveRecord::Migration
def change
create_table :users_groups, id: false do |t|
t.integer :user_id, index: true
t.integer :group_id, index: true
end
end
end
user.groups
group.users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment