How can I read only the lastChild along with parentObject
Parent {
hasMany[children: Child]
}
here is my code
Parent.withCriteria() {
eq("active", true)
children {
order("dateCreated", "desc")
maxResults(1)
}
}
But not working. How can I read Parent with last updated child
hasManyin GORM/Hibernate does NOT have a filter semantics and always returns all referenced objects.In a straight-forwad case you have to fire 2 queries: to find all
Parentsand to find all last updated children.Another option would be to reverse the search logic: look for children 1st, group them by
lastUpdatedand then pull their parents. Of course, you must have a back-ref from Child to Parent:Then the query could look something like: