> class House < ActiveRecord::Base > belongs_to :country > belongs_to :cities > belongs_to :streets > end > > Now...if i want to create a house like this: > > @street = Street.find(1) > @house = @street.houses.new > @house.name = "Burlington house" > @house.save > > Now...only the street_id key is set in the house record...But not > city_id and country_id... > Is there an ORM way to let active record do the job ?
That is the ORM way. The problem lies in your design (i.e. associations). A country has many cities. Cities have many streets. These streets contain houses. Sure a house belongs to a city, but given the additional entities involved the above model makes more sense. @house = some_city.streets.find(1).houses.create(:name=>'Adelitas') --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---