假设我在表上有几个默认范围
class User < ActiveRecord::Base
default_scope where(:first_name => 'Allen') # I know it's not realistic
default_scope where(:last_name => 'Kim') # I know it's not realistic
default_scope where(:deleted_at => nil)
end
>> User.all
User Load (0.8ms) SELECT `users`.* FROM `users`
WHERE `users`.`first_name` = 'Allen'
AND `users`.`last_name` = 'Kim' AND (`users`.`deleted_at` IS NUL
L)
当我想找到不考虑 first_name 的用户时,我唯一能做的就是取消它的范围并再次重新定义默认范围
User.unscoped.where(:deleted_at=>nil).where(:last_name=>"Kim")
有没有办法取消某些键的范围,如下所示?
User.unscoped(:first_name)