C. Ross
C. Ross

Reputation: 31848

How to query by relationship and?

I have a grails domain class Character

class Character {

    String name
    int level
    boolean alive
    Player player

    static constraints = {
        name(blank:false, unique:true)
        level(min:1)
        player(nullable:false)
    }
}

I want to query for a character with a specified player, where the value of alive is "true". I tried using the following, but it

Character.findByPlayerAndAliveEqual(p, true)

But it generates an exception

No signature of method: static java.lang.Character.findByPlayerAndAliveEqual() is applicable for argument types: (com.thestreetsgame.security.Player, java.lang.Boolean) values: [com.thestreetsgame.security.Player : 1, true] 

I've also tried findByPlayerAndAlive, with the same result. How can I make this gorm query work?

Upvotes: 1

Views: 117

Answers (1)

C. Ross
C. Ross

Reputation: 31848

Oops, the important part of the exception just jumped out at me.

java.lang.Character

I was trying to do a lookup on the core java class instead of my domain class. Need to always use the fully qualified name, or change the name of the class.

For the time being I've fully qualified the reference, and it is working.

Upvotes: 2

Related Questions