Does anyone have a good example of adding a name to a relationship field in keystonejs? Right now it just saves an id so if I need to display that fields name in a jade template I need to also query that relationship model. Ideally something like this:
var keystone = require('keystone'),
Types = keystone.Field.Types;
/**
* Titles Model
* =============
*/
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();
Would save like this:
title = {
name: 'name',
room: 3141234123442,
businessUnit: {
name: 'business name',
_id: 123412341234
}
}
If no example if someone could just walk me through the best practice on doing a custom relationship field type to store value and id from the relationship select menu I could probably figure it out. This site will have 1000's of documents in each collection so I need to focus on performance and best practices now.