I have the following model: 1 Person to many Participant ('enrollments' is the navigator)
If I just want the name of the person, and the date of all enrollments, this doesn't work:
EntityQuery.from('Person').where('id','eq',id)
.select('firstName, lastName, enrollments.dateEnrolled')
.execute()
I get an error:
Unable to locate property 'DateEnrolled' on type
'System.Collections.Generic.ICollection`1[EntityClasses.Participant]'
What is the proper syntax for projections of fields on one-to-many relationships?
There is no really good way to express this in a single query. You can get all of the "enrollments" but you will need to select out the "dateEnrolled" on the client.
EntityQuery.from('Person').where('id','eq',id)
.select('firstName, lastName, enrollments').expand("enrollments")
.execute().then(function(data) {
// extract "dateEnrolled" from data.results
});
Alternatively, you can use a 'named query" on the server that performs the projection there and simply query the projection from the client.
Or perhaps better would be to invert your query. Something like this: ( assuming you have a scalar property named 'Person' on your 'Enrollment' type).
EntityQuery.from('Enrollments').where('person.id','eq',id)
.select('person.firstName, person.lastName, dateEnrolled').expand("person")
.execute().then(...);