Here's the domain classes I'm working with:
class Foo {
String name,
type
static hasMany = [ bars: Bar ]
List bars
static mapping = {
bars lazy:false
}
}
class Bar {
String value
static belongsTo = Foo
}
I've written some Criteria queries in order to give the users an interface to query from. The interface provides a drop down in order to select a specific value for Bar. The problem happens when a user tries to specify a value for the Bar class, and wants to get the related Foos. Here's the Criteria query:
def query = {
and {
if (params.name && params.name != '') {
ilike('name', "%${params.name}%")
}
if (params.type && params.type != '') {
ilike('type', "%${params.type}%")
}
if (params.value && params.value != '') {
bars {
eq("value", params.value)
}
}
}
}
def results = Foo.createCriteria().list(params,query)
Essentially, it looks like what's happening is that only the Bars that match the specified value are being returned with the Foo object, even if the Foo object has other Bars that don't match that object. I want it to return all of the Bars, since I'm querying for Foo's with matching Bars.
Any ideas? Further clarification needed?