Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. has_one :city
  3. has_one :state
  4. has_one :country
  5. end
  6.  
  7. class City < ActiveRecord::Base
  8. belongs_to :state
  9. belongs_to :user
  10. end
  11.  
  12. class State < ActiveRecord::Base
  13. has_many :cities
  14. belongs_to :country
  15. belongs_to :user
  16. end
  17.  
  18. class Country < ActiveRecord::Base
  19. has_many :states
  20. belongs_to :user
  21. end
  22.  
  23. city = City.create(name: "New York City")
  24. city.state = state
  25.  
  26. state = State.create(name: "New York")
  27. state.country = country
  28.  
  29. country = Country.create(name: "United States")
  30.  
  31. user = User.create(name: "John Doe")
  32. user.city = City.first
  33. user.state = user.city.state
  34. user.country = user.state.country
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement