If I have a scope with a lambda and it takes an argument, depending on the value of the argument, I might know that there will not be any matches, but I still want to return
In Rails 4, a chainable ActiveRecord::NullRelation
will be returned from calls like Post.none
.
Neither it, nor chained methods, will generate queries to the database.
According to the comments:
The returned ActiveRecord::NullRelation inherits from Relation and implements the Null Object pattern. It is an object with defined null behavior and always returns an empty array of records without quering the database.
See the source code.