gorm - Grails - find where date ranges overlap -
i have grails domain object startdate , enddate property.
what's best way find objects range [startdate, enddate] overlaps specified date range? know how in sql wonder if there's grails/gorm magic more succinctly.
also, enddate optional property.
the sql / jpql query
from myobject obj obj.startdate <= ?1 , (obj.enddate null or obj.enddate >= ?2)
two ways embrace grails/gorm in case:
lazy:-
def today = new date() def query = myobject.where { startdate <= (today - 10) && (enddate == null || enddate >= today + 10) } def listofmyobjects = query.list()
eager:-
def today = new date() def listofmyobjects = myobject.findall {//or find{} if need first occurance startdate <= (today - 10) && (enddate == null || enddate >= today + 10) }
Comments
Post a Comment