This project is archived and is in readonly mode.

#326 ✓duplicate
Comron Sattari

Query generated with :include does not have join clause

Reported by Comron Sattari | June 3rd, 2008 @ 10:31 PM

Recently, when we were upgrading from 1.2.x all the way to 2.1 we noticed some of the rails generated queries were not valid SQL. We tracked the problem down to the new feature in rails of loading :included tables in separate queries, the feature is smart enough to revert to the old massive OUTER JOIN style query when the :included tables are used in a :conditions clause.

The problem we were having was that the feature doesn't extend the same kindness to tables found in our :order clause. Turns out only the conditions_tables method looks to the scope to find tables, we are using with_scope() with an :order clause and it was being ignored.

We quickly patched our own copy of rails' order_tables to look like this:

        def order_tables(options)
          orders = [scope(:find, :order), options[:order]].flatten.join(', ')
          orders.scan(/([\.\w]+).?\./).flatten
        end

but couldn't find an appropriate test to change to test for the new expected behavior. Is this a bug or a feature =)? Is using :order with with_scope wrong?

Thanks,

COmron

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages