I have two domain classes Users and Projects like following
Users{
String firstName
String lastName
String emailAddress
static hasMany = [projects:Projects]
}
class Projects {
String projectName
String description
Users projectLead
Date completionDate
static belongsTo = Users
}
Here completionDate == null means the project has not yet been completed.
Now I want to send an email reminder to each user about their incomplete projects, How can write a query to retrieve incomplete projects per user?
I was thinking on following lines but am still not able to go ahead. In order to send an email I will need users emailid, all incomplete projects and names of them
def users = Users.list()
for(user in users){
user.projects.find{it.completionDate==null}
}
Is it possible to use createCriteria in such a case?
I think this should work:
That should just return you the Users with incomplete projects, and the
projectsproperty for eachUserwill only contain the incomplete projects. If you want the Users to have all of their projects loaded, I believe you need to use an aliasTesting…
Given the User class:
And the Project class:
This integration test passes (hopefully the asserts explain it)
(this is the sql the criteria query executes in this instance):