|
Hi, can anyone help with this GORM query to match multiple
associations on an object? class Zoo { String name static hasMany = [animals:Animal] static namedQueries = { // SEARCH1 match any of a list of animals searchOr { searchAnimals -> or { searchAnimals.each { name -> animals { eq('name', name) } } } } // SEARCH2 match ALL of a list of animals searchAnd { searchAnimals -> and { searchAnimals.each { name -> animals { eq('name', name) } } } } } } class Animal { String name } SEARCH1 will happily match a zoo with any of a list of animals, but how should SEARCH2 be written to get zoos which have ALL animals in the supplied list? Any help much appreciated. Cheers, Alex --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
(Cross-posted to stackoverflow:
http://stackoverflow.com/questions/10529243/grails-gorm-query-to-match-multiple-associated-objects) On 9 May 2012 18:25, Alex Anderson <[hidden email]> wrote: > Hi, can anyone help with this GORM query to match multiple > associations on an object? > > class Zoo { > String name > static hasMany = [animals:Animal] > > static namedQueries = { > // SEARCH1 match any of a list of animals > searchOr { searchAnimals -> > or { > searchAnimals.each { name -> > animals { > eq('name', name) > } > } > } > } > > // SEARCH2 match ALL of a list of animals > searchAnd { searchAnimals -> > and { > searchAnimals.each { name -> > animals { > eq('name', name) > } > } > } > } > } > } > > class Animal { > String name > } > > SEARCH1 will happily match a zoo with any of a list of animals, but > how should SEARCH2 be written to get zoos which have ALL animals in > the supplied list? > > Any help much appreciated. > > Cheers, > > Alex |
| Powered by Nabble | Edit this page |
