This project is archived and is in readonly mode.
ActiveRecord - named_scope using ':columns' as the name is buggered
Reported by FlyboyArt | March 13th, 2010 @ 02:56 PM
I spent all afternoon on this one but it's rewarding to find it....
Given a model called "Article"
I have a list of named_scope directives as follows:
named_scope :active, :conditions => {:active => true}
named_scope :journal, :conditions => {:department => 0}
named_scope :features,:conditions => {:department => 1}
# NOTE: If you use :columns here, it's buggered!
named_scope :column, :conditions => {:department => 2}
named_scope :news, :conditions => {:department => 3}
named_scope :tips, :conditions => {:department => 4}
If I use :column for a name, it works fine. If I use :columns for a name the model's attributes are not accessible in script/console or when rails is running normally.
-Art
Comments and changes to this ticket
-
Ryan Bigg March 14th, 2010 @ 02:11 AM
columns is a reserved class method on ActiveRecord. Perhaps named_scope should error if you try to define a method that is already defined?
-
David Trasbo April 11th, 2010 @ 09:19 PM
- Assigned user set to Ryan Bigg
In edge Rails you will be warned if defining a scope results in a method being overridden. This ticket can be closed.
-
Ryan Bigg April 11th, 2010 @ 09:32 PM
- State changed from new to resolved
if !scopes[name] && respond_to?(name, true) logger.warn "Creating scope :#{name}. " \ "Overwriting existing method #{self.name}.#{name}." end
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>