I'm trying a query in Grails 1.2.1, find all products by tenant type.
My solution works but is very inefficient, first I retrieve all products and then find all matching results for the given tenant.
I found a related bug in JIRA: Enum as collection
class Product {
Set<TenantType> tenants
static hasMany = [tenants: TenantType]
}
enum TenantType {
BICYCLE,
MOTORCYCLE
}
def tenant = TenantType.BICYCLE
Product.list().findAll { product -> tenant in product.tenants }
Is there a more efficient way of querying for this data?