Skip to content

Instantly share code, notes, and snippets.

@listrophy
Created October 15, 2011 23:32
Show Gist options
  • Save listrophy/1290316 to your computer and use it in GitHub Desktop.
Save listrophy/1290316 to your computer and use it in GitHub Desktop.
simple has_and_belongs_to_many example (from memory...)
class CreateJoinTableForDomainsAndUsers < ActiveRecord::Migration
def change
create_table :domains_users, id: false do |t|
t.integer :user_id
t.integer :domain_id
end
add_index :domains_users, [:user_id, :domain_id]
add_index :domains_users, [:domain_id, :user_id]
end
end
class Domain < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :domains
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment