I don't know if this query is possible using grails executeQuery. I made sample a domain class:
class Child {
String firstName
String lastName
String nickName
}
and here is my boot strap:
class BootStrap {
def init = { servletContext ->
def childOne = new Child(firstName: 'Poliwag', lastName:'Wrath', nickName: 'taurus')
def childTwo = new Child(firstName: 'Poliwarp', lastName: 'Wrath', nickName:'libra')
def childThree = new Child(firstName: 'Poliwag', lastName: 'Wrath',nickName:'aries')
def childFour = new Child(firstName: 'Poliwag', lastName: 'Wrath',nickName:'virgo')
childOne.save(flush: true, failOnError: true)
childTwo.save(flush: true, failOnError: true)
childThree.save(flush: true, failOnError: true)
childFour.save(flush: true, failOnError: true)
}
}
as you notice, i have 2 sample data entries that have the same firstName & lastName property, they only differ in nickName property. What I want to get in executeQuery is a list of entry whose firstName & lastName properties is the same from another 2 entries. is it possible to use an operator with count(...) in grails executeQuery? I think this is the equivalent code for this using dynamic finders:
def list = []
def c = Child.countByFirstNameAndLastName('Poliwag',Wrath)
if (c == 2) {
list.add(Child.findByFirstNameAndLastName('Poliwag','Wrath'))
}
I think it will save more lines of code if I use executeQuery if possible. thanks..