Query : I like to know how one can get latest entry of a domain entity in Grails.
Problem domain:
class Parent {
String name
static hasMany = [children:Child]
}
class Child {
String name
Parent parent
static belongsTo = [parent:Parent]
}
Data model

Results
i like to pull record with id 4 and 7
where critria should be “get me last record of each parent where child’sname like ‘Rox%’
so far i have tried
SELECT
MAX(id)
FROM child
WHERE parent_id IN(SELECT
p.id
FROM parent AS p
JOIN child AS c
ON (c.parent_id = p.id
AND c.name LIKE 'Rox%'))
GROUP BY parent_id
thanks in advance.
Your description is a tad shady, but I think this is what you want:
Edit:
You changed your whole question around while I typed my answer out, changed it around to match.
Final edit:
Add sorting to children {} in the edited code to get the sorting you want.