I really don't understand the actual usecase of the *except* method
If I don't want a condition to apply in my _query_, then why should I add it?
After adding a condition, what is the point of removing it again. This how the
ActiveRecord::SpawnMethods is saying.
except is used when you want to use part of a relation but not necessarily the whole thing. It’s not always useful in application code, but when dealing with generic relations it can be really useful:
conditions = conditions.id
ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `exists?`." \
"Please pass the id of the object by calling `.id`"
return false if !conditions
relation = apply_join_dependency(self, construct_join_dependency)
return false if ActiveRecord::NullRelation === relation
relation = relation.except(:select, :order).select(ONE_AS_ONE).limit(1)
when Array, Hash
relation = relation.where(conditions)
unless conditions == :none
relation = where(primary_key => conditions)
except is used to remove parts of the relation that
exists? doesn’t want to use.
`except` is used when you want to use part of a relation but not
necessarily the whole thing. It's not always useful in application code,
but when dealing with generic relations it can be really useful:
GitHub - rails/rails at 44b7d6c41610bb8ddd058b3815543985f65bf7ad
Here, `except` is used to remove parts of the relation that `exists?`
doesn't want to use.
Very useful example. Does it mean, we can use it also *scope* or on *default
scope* ? Will it be a good choice although to use scope relation if it fits any
query, with some tailoring using *except* ?
Yep. There are also some related methods;
unscope. They allow somewhat finer control than