I am working on a keystonejs project here and am running into a problem with relationships between two models.
I have the below two models:
User model:
User.add({
name: { type: Types.Name, required: true, index: true },
email: { type: Types.Email, initial: true, required: true, index: true },
number: { type: Types.Number, index: true },
password: { type: Types.Password, initial: true, required: true }
}, 'Permissions', {
isAdmin: { type: Boolean, label: 'Can access Keystone', index: true },
}, 'Groups', {
groups: {type: Types.Relationship, ref: 'Group', many: true }
});
And I have a Group model
Group.add({
name: { type: String, required: true, index: true },
description: { type: String, initial: true, required: true, index: true}
});
I have a aggregate function that basically pulls all of the groups that have users in it
User.model.aggregate({$group:{'_id':'$groups'}}).exec(function(err,data){
console.log(data);
});
My problem is that the above aggregate only shows me my groups by their _id values and not their names.
How could I populate and show the names in the front end? Obviously the id's are necessary on the back end to reference but to the front end users that won't work.
Thanks