Created
November 23, 2011 10:53
-
-
Save tanelsuurhans/1388422 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 User | |
| has_many :city_users | |
| has_many :cities, :through => :city_users | |
| end | |
| class City | |
| has_many :city_users | |
| has_many :users, :through => :city_users | |
| end | |
| class CityUser | |
| belongs_to :user | |
| belongs_to :city | |
| end | |
| user = User.new | |
| city = City.new | |
| user.cities << city # add another city to a user | |
| user.city_ids = [1,2,3] # assign a bulk of city id-s directly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment