JustmeVSI
JustmeVSI

Reputation: 183

Restrict domain object retrieval from database based on a global criteria

Is it possible to restrict retrieval of objects based on a global criteria in grails?

Example:
There are objects in the database that have a status deleted. I don't want those objects to be returned when I make a query. For instance Object.all should not return objects that are marked as deleted.

I looked at the action listener method afterLoad() but could not figure out how it works or if it is the way to go. I also thought about metaprogramming but I don't really want to go that way.

Upvotes: 1

Views: 173

Answers (1)

dellyjm
dellyjm

Reputation: 426

marko is on point, namedQueries are the way to go. You could also have a base class that all domain objects inherit from with a property called Deleted which is set when you do whatever it is that causes a 'Delete'. Your find* queries can now say where not Deleted

Upvotes: 1

Related Questions