You cannot make it persist with Keystone, but you can make it pass the object according to your jade pattern.
You just need to “fill out” the relationship field according to the mongoose / mongodb functionality.
** So your businessUnit model might look like this:
var keystone = require('keystone'); var Types = keystone.Field.Types; var BusinessUnit = new keystone.List('BusinessUnit', { autokey: { from: 'name', path: 'key', unique: true }, plural: 'BusinessUnits' }); BusinessUnit.add({ name: { type: String, required: true }, }); BusinessUnit.relationship({ ref: 'Title', path: 'title', refPath: 'businessUnit' }); BusinessUnit.register();
Your header model as above
var keystone = require('keystone'), Types = keystone.Field.Types; var Title = new keystone.List('Title'); Title.add({ name: { type: String, required: true, initial: true }, room: { type: Types.Relationship, initial: true, required: true, ref: 'Screening', addNew: false }, businessUnit: { type: Types.Relationship, initial: true, required: true, ref: 'BusinessUnit', addNew: false } }); Title.defaultSort = '-createdAt'; Title.defaultColumns = 'name, room'; Title.register();
An important part of your controller might look like this:
//Get all Titles with their nested businessUnits. view.on('init', function(next) { keystone.list('Title').model.find() .populate('businessUnit') .exec(function(err, results) { if(err) { console.log(err); return next(err); } else { locals.data.titlesWithNestedBusinessUnits = results; next(err); } }); });
As a side note, this will only work one level in accordance with the .populate capabilities. If you want to go through some deep (rather ineffective), you can use the deep filling of the mongoose . https://github.com/buunguyen/mongoose-deep-populate .