grails - Search records bases on latest record in a hasmany relationship -
I have two domains
class domains {string name date date sorted date last update Fixed Static = ['Email'] is static Haimyanya = [domain BS: domain B] public string getEmail () {DomainB.mostRecentRecord (this) .get () ?. Email}} and
class domainb {String Email Date Date Created Date Last Updated Stable Stability = [Domain A: DomainA] Static nameQueries = {Most Recently Recorded {domainA - & gt; Eq 'domainA', domainA order ('dateCreated', 'desc') maxResults (1)}}} I need to get a list of all domains whose name starts with The "M" and latest domain B's records contain Gmail in their email properties. I tried createCriteria and hql but did not get the desired result, maybe I'm doing something wrong. The following is my current code
list & lt; Domain A & gt; listA = DomainA.findAllByNameIlike ("M%") list & lt; DomainB & gt; ListB = [] list a.each {entity -> DomainB domainB = DomainB.mostRecentRecord (entity) .get () if (domainB & amp; amp; amp; domainB.Mail.contains ('gmail')) {{{{{{}}}} > but it does not allow pagination and sorting on the page.
Do anyone have an idea of getting a list of all domains whose name starts with "M" and
Since you seek the most recent email You are required to see the maximum date on your second domain. You can write it using HQL and use Executex to pass your paging parameter. Just make an index on your dateCreated . FirstDomain.executeQuery ("FirstDomain fd, choose from seconddomain sd, where \ sd.firstDomain.id = fd.id and fd.name like: name and sd.email like: email \ and Sd.dateCreated = (Second Donan SD2 to sd2.firstDomain.id = fd.id)), [Max: '% gmail%', name: 'm%'], maximum max (select sd2.dateCreated), [max. : 10, Offset: 0]) : Just press the first domain controller
def fd // Most recent email Gmail FD = new firstname (name Is: MTAST ") fd.addToSecondDomain (email: 'yahoo.com')) fd.addToSecondDomain (New Second Domain (email: 'gmail.com')) fd.save (flush: true) // Fd.addToSecondDomain (new seconds domain (email: 'yahoo.com')) fd.addToSecondDomain (new secondsDemain (email: 'gmail.com')) .save (flush: true) // "mestst" firstdomain. First Damen FD from "FDAT" (FD) will return to SD card, where sd.firstDomain.id = fd.id and fd.name like: name and sd.email such as: email and sd.dateCreated = (second dimension SD2 Select the maximum (sd2.dateCreated) where sd2.firstDomain.id = fd.id), [email: '% gmail%', name: 'm%'])
Comments
Post a Comment