Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- has_one :city
- has_one :state
- has_one :country
- end
- class City < ActiveRecord::Base
- belongs_to :state
- belongs_to :user
- end
- class State < ActiveRecord::Base
- has_many :cities
- belongs_to :country
- belongs_to :user
- end
- class Country < ActiveRecord::Base
- has_many :states
- belongs_to :user
- end
- city = City.create(name: "New York City")
- city.state = state
- state = State.create(name: "New York")
- state.country = country
- country = Country.create(name: "United States")
- user = User.create(name: "John Doe")
- user.city = City.first
- user.state = user.city.state
- user.country = user.state.country
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement