/** * Count duplicate submissions within 45 days * SELECT count(l.id) * FROM lead AS l, submission AS s, buyerLog as bl * WHERE l.id = s.leadId * AND s.id = bl.submissionId * AND bl.leadBuyer = $buyerName * AND l.id != $lead.id * AND l.dateCreated::date > $daysAgo */protecteddefBooleanisDuplicateSubmission(Leadlead,ArrayList<String>buyerNames){defisDuplicate=falsedefdaysAgo=newDate()-45defcnt=Lead.withCriteria{not{idEq(lead.id)}and{le('dateCreated',daysAgo)submissions{buyerLogs{inList('leadBuyer',buyerNames)}}}projections{rowCount()}}return(cnt>0)}
Thanks to schmolly159 on the #grails freenode IRC channel for the examples and continued help.