Grails / GORM criteria query with hasmany String

前端 未结 3 868
天命终不由人
天命终不由人 2021-01-11 19:25

I have a domain object (Cat) like this:

class Cat {
   String name

   static hasMany = [
      nicknames: String
   ]
}

(A cat has a name,

3条回答
  •  情歌与酒
    2021-01-11 19:55

    After a lot of trying and researching, I found this will work with Grails 2.4.0, I don't know about older versions.

    Cat.withCriteria {
        createAlias('nicknames', 'n') 
        ilike 'n.elements', '%kitty%'
    }
    

    The trick is to use 'n.elements'

提交回复
热议问题