Philip Hallstrom
2006-Aug-09 20:22 UTC
[Rails] Bug in ActiveRecord 1.14.4 and select_limited_ids_list method using mysql?!?!
All -
I just upgraded to rails 1.1.5 (per the announcement) which also updated
active record to 1.14.4 (was 1.14.2). I know have a problem...
Author has many Articles...
@authors = Author.find(:all, :limit => 10,
:offset => 0
:include => [:articles],
:conditions => ["hide = ?", false],
:order => "lname ASC, fname ASC,
articles.created_at asc")
This used to generate this query:
SELECT DISTINCT authors.id
FROM authors LEFT OUTER JOIN articles ON articles.author_id = authors.id
WHERE (hide = 0)
ORDER BY lname ASC, fname ASC, articles.created_at asc
LIMIT 0, 10
and now it generates this query:
SELECT DISTINCT authors.id, lname, fname, articles.created_at
FROM authors LEFT OUTER JOIN articles ON articles.author_id = authors.id
WHERE (hide = 0)
ORDER BY lname ASC, fname ASC, articles.created_at asc
LIMIT 0, 10
The next query generated (the one that actually gets my data) is the
same except for the "authors.id IN" section, since the new query
returns
a lot more rows since articles.created_at is pretty much different all
the time.
So, I used to get a list of 10 authors. Now depending on how many
articles each author has, I get about 2.
In active records changelog I see the following commit for 1.14.3:
Associations#select_limited_ids_list adds the ORDER BY columns to the
SELECT DISTINCT List for postgresql. [Rick]
And looking through the code in
activerecord-1.14.4/lib/active_record/associations.rb
I see where and why that is happening (I''m ordering by a field not in
the model''s table).
But what I don''t understand is why this change was made, nor why it
says
"for postgresql", but I don''t see any casing to only do it
for
postgresql. I also don''t understand why the original query
isn''t the
desired behaviour.
Anyway, am I missing something obvious? Or is this a bug? Is there any
other info I can provide?
Thanks!
-philip
Maybe Matching Threads
- Bug in ActiveRecord 1.14.4 and select_limited_ids_list() ???
- Problem with setter override on ActiveRecord
- Patch: sftp client support of "ls [flags] [path [localfile]]" feature
- Problem with large join table and ActiveRecord
- Form Validation with non-model fields
