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://corelib.rubyonrails.org/classes/Array.html
Thanks in advance,
Steven.