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.

include field ignored

#620

I have a query like this:

item = Item.find(:all, order => [ "field(users.login, 'automated_user'), items.id DESC" ], :include => :user)

This fails in Rails 2.1 because the include is ignored.

The only way to get it working was to add an

:conditions => [ 'users.id IS NOT NULL' ] or in general anything involving a check of the user table.

Reported by Marcelo Barbudas · July 15th, 2008 @ 01:46 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Stephanie Collett
    Stephanie Collett

    This just got me today. Thanks for the work around.

    July 23rd, 2008 @ 12:31 AM

  2. Frederick Cheung
    Frederick Cheung

    The order option should be a string (you get away with passing a one element array because of Array's default to_s implementation. If you use a string then rails should notice that you are referencing the users table in your order option

    August 9th, 2008 @ 04:07 PM

  3. Marcelo Barbudas
    Marcelo Barbudas

    Indeed making it a string fixes the problem.

    After using conditions => [] for some time it feels naturally to use arrays for options in find methods.

    August 12th, 2008 @ 10:45 AM

  4. Tarmo Tänav
    Tarmo Tänav
    • State changed from new to invalid
    • Tag changed from activerecord to activerecord

    The docs do say that :order should be an sql fragment. This working with anything else is just a coincidence, though indeed that could be a surprise, but there isn't much that could be done here.

    September 18th, 2008 @ 05:26 AM