Reputation: 755
Assume the following:
class Thing {
String name
List<String> tags
static constraints = {
name(nullable: false)
tags(nullable: false)
}
}
I want to know if its possible, using GORM, to run a query for domain instances based on values in their respective lists
For instance: Are there dynamic GORM finders to query things like 'Find all Things that have the tag "Video" ', or 'Find all things with name = "Product1" that have the tag "Image" '
Just want to know if there's a nice concise way of doing this with Grails&Gorm, as opposed to retrieving a list of Things and iterating through it, finding the ones that have the appropriate tags and adding them to a results list.
Thanks!
Upvotes: 1
Views: 906
Reputation: 709
One way (although not necessarily the most efficient!) would be to return the whole list of Thing
s eg Thing.list()
and then filter the resulting list using findAll
.
List results = Thing.list().findAll{it.tags.contains("Image")}
How big is your list of Thing
s and associated Tag
s likely to be?
Upvotes: 1