Created
February 4, 2015 22:11
-
-
Save Aevin1387/157fef2d8e74b9045e7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < ActiveRecord::Base | |
has_many :people_places | |
has_many :places, through: :people_places | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersonPlace < ActiveRecord::Base | |
self.table_name = "people_places" | |
belongs_to :person | |
belongs_to :place | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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