Why aren't select statements merged among scopes?

Hi folks,

I hope you all had a great Christmas.

My mail's subject says it all..
I've been in quite a lot situations where I wanted to join data from
another table "transparently", using scopes.

By transparently I mean that columns from the joined table are merged
into the result set as if they were attributes of the actual model.

SQL makes this possible with the SELECT statement, where you can do
"SELECT donors.*, model_translations.content AS name INNER JOIN
model_translations ON ...." so that a donor's name is actually fetched
from another table but still available for sorting etc.

Now to implement such a behavior we first need to add the JOIN
statement to the finder's SQL which is easy using dynamic scopes.
The SELECT, however can't easily be added because it would override
Rails' default "donors.*"..

I'm willing to hack a patch if there is no particular reason for this
implementation but I wanted to check beforehand.



Hi Matt,

I can use :select, but it overrides any previous :selects defined in other scopes or even the default scope instead of merging with them to select all the fields.

I think we have with_exclusive_scope for this behavior and the default should be different.


I found a ticket on Lighthouse which addresses the same issue, hope
someone has an idea how to solve this: