Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active August 29, 2015 13:56
Show Gist options
  • Save Chryus/8899641 to your computer and use it in GitHub Desktop.
Save Chryus/8899641 to your computer and use it in GitHub Desktop.
Data modeling in rails: example of has_many :through migrations
class CreateCarrots < ActiveRecord::Migration
def change
create_table :carrots do |t|
t.string :color
t.timestamps
end
end
end
class CreateBunnies < ActiveRecord::Migration
def change
create_table :bunnies do |t|
t.string :name
t.timestamps
end
end
end
class CreateCommunities < ActiveRecord::Migration
def change
create_table :communities do |t|
t.integer :carrot_id
t.integer :bunny_id
t.timestamps
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment