> I think this should be exposed in some future version of Rails as an
> official API since it's so amazingly useful and gives you a hook into
> associations that is not possible any other way, but for now it's a
> private method and subject to change.

I agree on this one, I've been using the preload_associations stuff
quite a bit recently and it's great.

I figure there are two approaches, either do it data-mapper style and
automatically preload whenever any association gets accessed, or have
an explicit api.  I'm in favour of the second approach here, perhaps
something like:

@customers = Customer.find_by_sql(some_crazy_thing)
@customers.preload(:projects=>:tasks)
# DB not used from now on
puts @customers.map(&:projects).flatten.map(&:tasks).flatten.map(&:name)

That'd require an array subclass to be returned from all find calls,
but there's already stuff like this in Arel.

-- 
Cheers

Koz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" 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-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to