Every Application has a 1 to 1 relationship with a user. Every Trip has n Applications.
Here's my following code for populating all User (students) data in the Applications of all trips:
view.on('init', function(next) {
Trip.model.find()
.exec(function(err, trips){
keystone.populateRelated(trips, 'students[user]', function(err) {
locals.trips = trips;
next();
});
});
});
Here is the relationship that Trips has with Applications (StudentApp):
Trip.relationship({ ref: 'StudentApp', refPath: 'finalTrip', path: 'students' });
Now on the front end, I can print the stringified JSON of a user just fine:
each trip in trips
each app in trip.students
p=app.user
However the moment I try to access a field e.g app.user._id
I get the following error:
Cannot read property '_id' of undefined
I get the feeling it's an asynchronous issue, but I can't for the life of me figure out how to fix this.
Help would be much appreciated. Thanks.