chelder
chelder

Reputation: 3897

GORM querying: findAllByPropertyNotInList or findByPropertyNotInList do not exist, any equivalency?

The next code works:

self query1 = DomainClassExample.findAllByPropertyInList("hi","bye")

But if I add Not, the dynamic finder does not exist (it DOES exists: check the answer):

self query2 = DomainClassExample.findAllByPropertyNotInList("hi","bye")

I want to get all the DomainClassExample which don't have the property "hi" or "bye". Is there any dynamic finder for that purpose? Should I use the Where Query. How?

Upvotes: 0

Views: 90

Answers (2)

Rob
Rob

Reputation: 1260

In Grails 1.3.9, given the following domain:

class User {
    String username
    ....
}

this works in our application without any issues:

def userList = User.findAllByUsernameNotInList(["[email protected]","[email protected]"])

Upvotes: 0

Gregg
Gregg

Reputation: 35904

First, a minor correction. It's not a method expression. It's a dynamic finder. Now, as to your actual problem, you'll need to use the criteria API for this...

def c = DomainClassExample.createCriteria()
def matchingProperties = c.list {
    property {
        not { 'in'(["hi","bye"]) }
    }
}

You might run into an issue with the word 'property' and I haven't actually tested the code I just wrote. But that is the gist of it.

Upvotes: 1

Related Questions