Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Query generated with :include does not have join clause

#326

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

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • State changed from new to stale
    • Tag set to 2.1, activerecord, bug, eager_loading, include, joins, with_scope

    September 30th, 2008 @ 05:53 PM

  2. Frederick Cheung
    Frederick Cheung
    • Tag changed from 2.1, activerecord, bug, eager_loading, include, joins, with_scope to 2.1, activerecord, bug, eager_loading, include, joins, with_scope
    • State changed from stale to duplicate

    December 8th, 2008 @ 03:35 PM