gorm - Grails domain Named query for a list of string -


i have simple grails application. have domains below

class author implements serializable {    ....    static hasmany = [         book : book     ] }  class book implements serializable{     author author    genres genres    static belongsto = [author: author , genre: genres ]    static mapping = {     .....        author lazy: false    } }  class genres implements serializable{      string title  } 

now have requirement have list of genres title, need retrieve authors has atleast 1 book in 1 of genres. need write named query in author class. tried following query

hasgenre {cl ->     'book.genre.title' in cl } 

and pass list of string follows

 author.hasgenre(generetitlestringarray) 

but not seems working. have other straightforward named-queries works fine. when retrieve including "hasgenere" not seem affect retrieval. doing wrong? i'm quite new area

thanks in advance

have been using list() method? if no, must use entity namedquery, because namedquery return namedcriteriaproxy.class:

author = author.hasgenre(generetitlestringarray).list() 

for me such code working good, in author have:

static namedqueries = {     hasgenre { cl->         'book.genres.title' in cl     } } 

book same. genres must add dependency one-one(if haven't):

 static belongsto = [book: book] 

or 1 many:

static hasmany= [book: book] 

for me current code working good, luck.

p.s. i'm using grails 2.3.11


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -