1
votes

I've got a grails app, with two domain objects: Book, and Category.

Book has many categories (i.e., static hasMany = [categories: Category])

Can I use HQL to do something like:

Book.findAll("select b from Book as b 
                  where b != :book any elements(b.categories) in (:categories)", 
                  [book: myBook, categories: myBook.categories])

I can't seem to find examples where comparisons are made between two collections.

Most of the ones I've seen only has one collection

1
Please consider marking some of your questions as answered. - Igor

1 Answers

2
votes

Try some thing like this

Book.findAll("Select b from Book as b join b.categories as cat where cat in (:categories)", [categories:categories])

Modify other conditions as necessary