Skip to content

Instantly share code, notes, and snippets.

@tanelsuurhans
Created November 23, 2011 10:53
Show Gist options
  • Save tanelsuurhans/1388422 to your computer and use it in GitHub Desktop.
Save tanelsuurhans/1388422 to your computer and use it in GitHub Desktop.
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