Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1.3 unscoped scope

I've seen a lot of posts regarding this, but none seem to solve my problem. I have a default_scope on a model like so:

default_scope where(:is_active => true).order('LOWER(table.name)');

I have other (normal) scopes, and I want to create an inactive scope using unscoped. I would like to define it as a scope, but it only works when defined as a class method:

# works
def self.inactive
  unscoped { where(:is_active => false) }
end

# none of these work
scope :inactive, unscoped { where(:is_active => false) }
scope :inactive, with_exclusive_scope { where(:is_active => true) }
scope :inactive, unscoped.where(:is_active => false)
scope :inactive, lambda { unscoped { where(:is_active => false) } }
scope :inactive, unscoped { lambda { where(:is_active => false) } }
unscoped do
  scope :inactive, where(:is_active => false)
end

Is there a way that I missed, or do I have to use a class method to define this scope?

like image 573
sethvargo Avatar asked Jan 04 '12 21:01

sethvargo


1 Answers

There does not seem to be a way to do this. I opened an issue on the rails repo on github...

like image 109
sethvargo Avatar answered Nov 04 '22 15:11

sethvargo