Hello all -

I was asked to forward a bug found in Active Record 1.14.4 when I upgraded to Rails 1.1.5 today by <bitsweat>. He also suggested the 'HACK ALERT'... hope that's okay :)

The post in it's entirety is below.

Please let me know what else I can do to help resolve this...

From [EMAIL PROTECTED] Wed Aug  9 10:17:46 2006
Date: Wed, 9 Aug 2006 15:17:46 -0500 (CDT)
From: Philip Hallstrom <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Bcc: Philip Hallstrom <[EMAIL PROTECTED]>
Subject: 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 (line 1117)
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
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to