我看过很多关于这个的帖子,但似乎没有一个能解决我的问题。我有一个default_scope
这样的模型:
default_scope where(:is_active => true).order('LOWER(table.name)');
我有其他(普通)范围,我想inactive
使用unscoped
. 我想将它定义为一个范围,但它仅在定义为类方法时才有效:
# 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
有没有我错过的方法,或者我必须使用类方法来定义这个范围?