You do not have access to this ticket

This project is archived and is in readonly mode.

#2949 ✓resolved
Casper

Add magic encoding comment to generated files

Reported by Casper | July 24th, 2009 @ 04:54 PM

I just upgraded from Rails 2.2.2 to 2.3.3 and now ActiveRecord generates invalid SQL for named_scopes with :conditions + :joins.

Example extracted from my current project:

class ProviderIdMap < PCM::Model
  belongs_to :provider_id_map_category

  named_scope :defaults, :conditions => { :use_as_default => true }
  named_scope :tags,
              :joins      => [ :provider_id_map_category ],
              :conditions =>
              { "provider_id_map_category.provider_id_map_category_ud" => "TAG" }

  # ...
end

Doing:

ProviderIdMap.defaults.tags.count

in 2.2.2 generates the following SQL:

SELECT count(*) AS count_all 
FROM [provider_id_map] 
INNER JOIN [provider_id_map_category] 
      ON [provider_id_map_category].provider_id_map_category_id = 
         [provider_id_map].provider_id_map_category_id 

WHERE (([provider_id_map_category].[provider_id_map_category_ud] = 'TAG') 
  AND ([provider_id_map].[use_as_default] = 1))

Watch that last line - In 2.3.3 this is generated:

SELECT count(*) AS count_all 
FROM [provider_id_map]   
INNER JOIN [provider_id_map_category] 
      ON [provider_id_map_category].provider_id_map_category_id =
         [provider_id_map].provider_id_map_category_id  

WHERE (([provider_id_map_category].[provider_id_map_category_ud] = 'TAG'
  AND [provider_id_map_category].[use_as_default] = 1))

Yikes :( The use_as_default condition is mapped to the wrong table. It should go with provider_id_map, but instead in 2.3.3 it suddenly is attached to provider_id_map_category -> SQL Error:

  ActiveRecord::StatementInvalid: DBI::DatabaseError: S0022 (207) Invalid column name 'use_as_default'.

Comments and changes to this ticket

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>

Referenced by

Pages