I have two domains
class DomainA { String name Date dateCreated Date lastUpdated static transients = ['email'] static hasMany = [domainBs: DomainB] public String getEmail() { DomainB.mostRecentRecord(this).get()?.email } }
and
class DomainB { String email Date dateCreated Date lastUpdated static belongsTo = [domainA: DomainA] static namedQueries = { mostRecentRecord { domainA -> eq 'domainA', domainA order('dateCreated', 'desc') maxResults(1) } } }
My requirement is to get a list of all domains whose name starts with "M" and the last domainBs entry contains gmail in the email property.
I tried createCriteria and hql but didn't get the desired result, maybe I'm doing something wrong.
Below is my current code
List<DomainA> listA = DomainA.findAllByNameIlike("M%") List<DomainB> listB = [] listA.each { entity -> DomainB domainB = DomainB.mostRecentRecord(entity).get() if (domainB && (domainB.email.contains('gmail'))) { listB.add(domainB) } }
but this does not allow pagination and sorting.
Maybe someone has an idea to get a list of all domains whose name starts with "M" and the last domainBs contain gmail in the email property using createCriteria or hql or in any other way.
source share