This project is archived and is in readonly mode.

#5353 ✓stale
Brian Underwood

ActiveRecord adds comma to query's column list when referring to a model with a default_scope select()

Reported by Brian Underwood | August 10th, 2010 @ 09:21 PM

I have two basic models (sample Rails app with a failing test attached):

class Bar < ActiveRecord::Base
  default_scope select('id')
  has_many :bazs
end
class Baz < ActiveRecord::Base
  belongs_to :bar
end

When I try to refer to a "bar" object on a "Baz" object, I get an error (Either a PGError or SQLite3::SQLException in the case of my sample app). This seems to do with having a default_scope with a select() scoping on the targetted object.

When I go to belongs_to_association.rb and comment out the following line in BelongsToAssociation#find_target it seems to work fine:

            :select     => @reflection.options[:select],

That's obviously not a solution, but it might narrow down the search for the issue.

I'm using:
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10.4.0]
Rails 3.0.0.rc

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>

Attachments

Pages