I have a model which has a field called deleted, which is used to mark those deleted items.
So normally I would just want to query those having deleted = false items, and in some special cases to list those deleted items for restoring.
Is it possible to do that? What I could do now is just using a named scope having :conditions => {:deleted => false}
Is there a better way to do it so that When I do Item.other_named_scope, I could find all those not-deleted items?
You can use default_scope for this.
Now all queries to the
Postmodel will be onACTIVEposts. When you want to override this behavior usewith_exclusive_scope:Reference:
Link 1
Caveat
The default_scope affects every finder call. It should be used with care and with full awareness of the unwanted side-effects.