Search code examples
grailsgrails-orm

Ignoring "Inactive" Entries from Every Search Method


I'm using a legacy database in a read only fashion. I have a user domain that includes a flag if the user is active or not. Is there a way when calling search methods like findAll to always ignore inactive users without removing them from the database or specifically in every search query?


Solution

  • You have two options. Either add a Hibernate Filter which is your most transparent option, or to add a named query like

    static namedQueries = {
        active {
            ne 'inactive', true
        }
    }
    

    which will allow you to do

    User.active.findAllBy...()