This project is archived and is in readonly mode.
Adding a scope to ActiveRecord:Base throws undefined method exception
-
Saimon Moore
- Tag set to activerecord rails3
-
Saimon Moore
- Tag changed from activerecord rails3 to activerecord rails3, ruby-1.9.1
-
Piotr Sarnacki
- Importance changed from to Low
I don't know if we should support that kind of scopes declaration. The more appropriate in that case would be to just use class method, as you're reopening base class:
def self.random(lt) where("created_at < ?", Time.now.utc).order('RAND()').limit(lt) end -
Duke
I'm running across this as well. Every model here has a possible polymorphic relationship with Starlight.
module ActiveRecord
class Basehas_many :starlights, :as => :entity, :dependent => :destroy def starlight Starlight.for(self) end scope :order_by_starlight, joins(:starlights).group('starlights.id').having('max(starlights.id)').order('starlights.value')end end
I require order_by_starlight to be composable, so I can say, for instance, Entry.where(:user => current_user).order_by_starlightThis seems a good use case for adding scope to Activerecord::Base.
-
Duke
Yes, I see with Arel a class method is composable.