This project is archived and is in readonly mode.

#3137 ✓stale
Rob Worley

PostgreSQLAdapter discards parts of ORDER BY clause when eager loading

Reported by Rob Worley | September 2nd, 2009 @ 08:09 PM | in 2.3.6

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 }

Comments and changes to this ticket

  • Rob Worley

    Rob Worley September 2nd, 2009 @ 08:11 PM

    • Tag changed from 2.3.2, eager, eagerloading, eager_loading, postgres, postgresql to 2.3.3, eager, eagerloading, eager_loading, postgres, postgresql
  • CancelProfileIsBroken

    CancelProfileIsBroken September 25th, 2009 @ 12:35 PM

    • Tag changed from 2.3.3, eager, eagerloading, eager_loading, postgres, postgresql to 2.3.3, bugmash, eager, eagerloading, eager_loading, postgres, postgresql
  • Rizwan Reza

    Rizwan Reza January 21st, 2010 @ 07:01 AM

    • 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!

  • Rizwan Reza

    Rizwan Reza March 27th, 2010 @ 01:24 PM

    • State changed from “open” to “stale”

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>

Attachments

Pages