How to remove the default part in Arel

Let's say that I have multiple default fields in a table

class User < ActiveRecord::Base
  default_scope where(:first_name => 'Allen')  # I know it not realistic
  default_scope where(:last_name => 'Kim')     # I know it 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)

and when I want to find users with whatever first_name is, only I can do that without loosening it up and redefining the default scope again

User.unscoped.where(:deleted_at=>nil).where(:last_name=>"Kim")

      

Is there a way to trim certain keys like below?

User.unscoped(:first_name)

      

+3


source to share


1 answer


No, it unscoped

does not accept parameters.
it seems that in your case you are better off defining a normal scopes

(was :) named_scopes

.



you should only use default_scopes if you need data always (or almost) as defined in default_scope

.

+2


source







All Articles