Overriding a Rails default_scope

ruby-on-rails

Solution

Short answer: Do not use `default_scope` unless you really have to. You'll probably be better off with named scopes. With that said, you can use `with_exclusive_scope` to override the default scope if you need to.

Have a look at this question for more details.

Problem

If I have an ActiveRecord::Base model with a default-scope: ``` class Foo < ActiveRecord::Base default_scope :conditions => ["bar = ?",bar] end ``` Is there any way to do a `Foo.find` without using the `default_scope` conditions? In other words, can you override a default scope? I would have thought that using 'default' in the name would suggest that it was overridable, otherwise it would be called something like `global_scope`, right?

Original source

Related problems