Como consultar uma lista ordenando pela maior data de um objeto filho (Criteria)
20/06/2021 00:44
class Entity {
?static hasMany = [childrens: Children]}
class Children {
?Date date
}
SELECT
? *
FROM
? entity
INNER JOIN
? children c1 ON c1.entity_id = entity.idWHERE c1.date =
(SELECT MAX(c2.date) FROM children c2 WHERE c2.entity_id = c1.entity_id)
ORDER BY c1.date DESC
Entity.createCriteria().list(params) {
childrens {
projections {
groupProperty 'entity'
max 'date', 'maxDate'
}
}
order 'maxDate', 'desc'
}
Para se registrar, clique aqui.