It sounds like what you're looking for is default_scope
, documented here in the Rails API.
So, your model change would be something like:
class ModelName
default_scope where(:duplicate => false)
...
def self.include_alleged_duplicates
unscoped
end
end
unscoped
does just that, it runs with zero scopes on the model. See the documentation for unscoped.
The only gotcha with default_scope
is it is used on every relation in the model. Just like in your example:
ModelName.all
with a default_scope
will perform ModelName.where(:duplicate => false).all
If you find yourself using unscoped
more and more, you might want to consider reversing your logic to make the duplicate records the default_scope
and unique records the unscoped
.
Hope this helps!