This project is archived and is in readonly mode.
include field ignored
Reported by Marcelo Barbudas | July 15th, 2008 @ 01:46 AM | in 2.x
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.
Comments and changes to this ticket
-
Frederick Cheung August 9th, 2008 @ 04:07 PM
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
-
Marcelo Barbudas August 12th, 2008 @ 10:45 AM
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.
-
Tarmo Tänav September 18th, 2008 @ 05:26 AM
- 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.
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>
People watching this ticket
Tags
Referenced by
- 106 authenticity_token appears in URLs after AJAX GET request See line #620 of ActionView::Helpers#options_for_ajax her...