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.

PostgreSQLAdapter discards parts of ORDER BY clause when eager loading

#3137

add_order_by_for_association_limiting! assumes that you will only use DESC or ASC when ordering rows, but postgres also supports NULLS FIRST and NULLS LAST options.

When using eager loading, something like this named scope...

named_scope :latest_first, :order => "completed_at DESC NULLS LAST"

would actually generate "ORDER BY completed_at".

I've attached an initializer I'm using to monkey-patch the culprit. It's a one line change:

order.map! { |s| $1.upcase if s =~ /\b((asc|desc).*)$/i }

Reported by Rob Worley · September 2nd, 2009 @ 08:09 PM

State: stale
Milestone: 2.3.6
Assigned to: nobody
Importance: Low

Activity

  1. Rob Worley
    Rob Worley
    • Tag changed from 2.3.2, eager, eagerloading, eager_loading, postgres, postgresql to 2.3.3, eager, eagerloading, eager_loading, postgres, postgresql

    September 2nd, 2009 @ 08:11 PM

  2. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, eager, eagerloading, eager_loading, postgres, postgresql to 2.3.3, bugmash, eager, eagerloading, eager_loading, postgres, postgresql

    September 25th, 2009 @ 12:35 PM

  3. Rizwan Reza
    Rizwan Reza
    • State changed from new to open
    • Tag changed from 2.3.3, bugmash, eager, eagerloading, eager_loading, postgres, postgresql to 2.3.3, eager, eagerloading, postgres, postgresql
    • Milestone set to 2.3.6

    Rob, can you provide a failing test patch? Also, if it is not applicable in current Rails versions, do let us know. Thanks!

    January 21st, 2010 @ 07:01 AM

  4. Rizwan Reza
    Rizwan Reza
    • State changed from open to stale

    March 27th, 2010 @ 01:24 PM