Appending to the eager loading query select phrase just makes it
easier to blow your leg off (eg. because you don't know what the
aliased field names are, etc) without offering much more capability.
There are already thousands of edge cases like this that ActiveRecord
can't reasonably support because of the parity mismatch to raw SQL.
In these types of situations a much more powerful technique is to
manually hydrate your associations. If a Teacher has_many :students
then you can hydrate like this:
@teachers = Teacher.all
Teacher.send(:preload_associations, @teachers, [:students])
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.
On Nov 9, 1:40 pm, Mathieu Jobin <
somek...@gmail.com> wrote:
> Hi everyone,
>
> this is about
http://dev.rubyonrails.org/ticket/7147
> which has been close as wont fix. it seems like I cannot post comment on
> this bug anymore...
> neither my account (somekool) have the right to create new tickets.
>
> anyhow. I was looking at using both :select and :include in a query but
> could not as they are mutually exclusive. they I found this ticket close as
> won't fix.
>
> I understand the initial request is rather difficult to implement without
> getting important performance drawbacks.
> but I think this could be solved by adding a new attributes such as
> :select_append
>
> so a query would look like this
>
> Store.find :all,
> :select_*append* => 'sum(books.price * books.stock) as total_inventory',