Skip to content

Instantly share code, notes, and snippets.

@alecslupu
Created April 30, 2013 08:40
Show Gist options
  • Save alecslupu/5487429 to your computer and use it in GitHub Desktop.
Save alecslupu/5487429 to your computer and use it in GitHub Desktop.
Basic HABTM
class User < ActiveRecord::Base
has_and_belongs_to_many :skills
end
class Skill < ActiveRecord::Base
has_and_belongs_to_many :users
end
class CreateSkillsUsers < ActiveRecord::Migration
def change
create_table :skills_users do |t|
t.integer :skill_id
t.integer :user_id
end
add_index :skills_users, [:skill_id, :user_id], :unique => true, :name => :skills_users1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment