OK, I added a town_id to each house and it's working fine, but if there's a method I've missed that handles this automagically, it'd be great to know.
s. On Sep 8, 10:21 pm, steven_noble <[email protected]> wrote: > Let's say... > > class Town < ActiveRecord::Base > has_many :streets > has_many :houses, :through => :streets > end > > class Street < ActiveRecord::Base > has_many :houses > end > > Then we can find individual streets and houses like this... > > @first_town = Town.find(:first) > @first_towns_first_street = @first_town.streets.first > @first_streets_first_house = @first_town_first_street.house.first > > We can also find arrays of streets and houses like this... > > @first_town_all_streets = @first_town.streets > @first_street_all_houses = @first_street.houses > > But what is the correct syntax for the kind of array I'm trying to > generate here? > > @first_town_all_houses = @first_town.streets.houses > > I'm presuming I can create a methods that iterates through the streets > array, generates an array of houses for each street, and adds that > array to a larger array of my own creation. Likewise, I'm assuming I > can assign a town_id to each house whenever I create it, just as I > automatically assign it a street_id through create/build. However, I'm > hoping there's an existing method that'll just magic up the results. > Problem is, so far I haven't found it on either of the following > pages: > > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet...http://corelib.rubyonrails.org/classes/Array.html > > Thanks in advance, > > Steven. --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

