Let's say I have the following classes:
abstract class Fruit {
String name
static mapping = {
discriminator column: 'type'
}
class Banana extends Fruit {
static mapping = {
discriminator: 'Banana'
}
}
class Apple extends Fruit {
static mapping = {
discriminator: 'Apple'
}
}
I need to implement a search algorithm such that, given a JSON string, I can find a particular Fruit instance in the DB. For example:
{
"type": "Apple"
"name": "Green"
}
or
{
"type": "Banana"
"name": "Green"
}
Problem is, fruits can have the same name, so if I just do a search for this:
Fruit.getByName('Green')
It might return the Apple
or the Banana
. I need to be able to filter it by its type as well based on the type, something like:
Fruit.getByNameAndType('Green', 'Apple')
How do I do this in Grails?
Should this meet your need?