Skip to content

Instantly share code, notes, and snippets.

@Aevin1387
Created February 4, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aevin1387/157fef2d8e74b9045e7f to your computer and use it in GitHub Desktop.
Save Aevin1387/157fef2d8e74b9045e7f to your computer and use it in GitHub Desktop.
class AddPersonPlacesAndPeoplePlaces < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.timestamps
end
create_table :places do |t|
t.string :name
t.timestamps
end
create_table :people_places do |t|
t.references :person, index: true
t.references :place, index: true
end
end
end
class Person < ActiveRecord::Base
has_many :people_places
has_many :places, through: :people_places
end
class PersonPlace < ActiveRecord::Base
self.table_name = "people_places"
belongs_to :person
belongs_to :place
end
class Place < ActiveRecord::Base
has_many :people_places
has_many :people, through: :people_places
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment