views:

879

answers:

2

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?

+2  A: 

Short answer: Don't 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.

Pär Wieslander
Thanks for the link to the previous question
Gareth
+2  A: 

You can override a default scope using the with_exclusive_scope method. So:

foos = Foo.with_exclusive_scope { :conditions => ["baz = ?", baz] }
John Topley