Grails
›
Grails - user
Search
everywhere
only in this topic
Advanced Search
Help needed to query association multiple times
Classic
List
Threaded
♦
♦
Locked
2 messages
mikemike
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Report Content as Inappropriate
♦
♦
♦
♦
Help needed to query association multiple times
This post has NOT been accepted by the mailing list yet.
Example:
A book can have many tags for example romance, fiction, children, adult
A book like Harry Potter has tags including fiction, fantasy, children, etc
Class is defined such
class book {
static hasMany = [tags Tag]
}
Now my question is how to query all books that have both fantasy and children tags?
def result1 = Book.createCriteria().list{
tags{
eq("tagValue", "fantasy" )
};
}
works fine to retrieve fantasy books, but I just cannot make a criteria for "fantasy AND children".
def result1 = Book.createCriteria().list{
and {
tags{
eq("tagValue", "fantasy" )
}
tags{
eq("tagValue", "children" )
}
}
}
returns empty results
If querying by criteria is not possible for such structure, please let me know if there are alternative efficient ways to query.
Thank you very much.
julianhall
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Report Content as Inappropriate
♦
♦
♦
♦
Re: Help needed to query association multiple times
This post has NOT been accepted by the mailing list yet.
Have you tried:
tags{ and { eq("tagValue", "fantasy" ) eq("tagValue", "children" ) } }
Loading...
Powered by
Nabble
Edit this page