2016-05-17 9 views
0

Also versuche ich das 'Pronouns'-Modell vom' Satz'-Modell aus 'TestGenerator'-Modell zu bekommen. Und ich habe IDs, aber kein Modell.Wie man das Beziehungsmodell in Keystone.js bekommt

TestGenerator Modell

var TestGenerator = new keystone.List('TestGenerator', { 
    map: { name: 'title' }, 
    autokey: { path: 'slug', from: 'title', unique: true } 
}); 

TestGenerator.add({ 
    title: { type: String, required: true }, 
    sentences: { type: Types.Relationship, ref: 'Sentence', many: true }, 
}); 

TestGenerator.register(); 

var Sentence = new keystone.List('Sentence', { 
    map: { name: 'title' }, 
    autokey: { path: 'slug', from: 'title', unique: true } 
}); 

Satz Modell

Sentence.add({ 
    title: { type: String, required: true }, 
    pronouns: { type: Types.Relationship, ref: 'Pronoun', many: true }, 
    verbs: { type: Types.Relationship, ref: 'Verb', many: true }, 
}); 

Sentence.relationship({ ref: 'TestGenerator', path: 'sentences' }); 

Sentence.register(); 

Ponoun Modell

var Pronoun = new keystone.List('Pronoun', { 
    map: { name: 'english' }, 
    autokey: { path: 'slug', from: 'english', unique: true }, 
}); 

Pronoun.add({ 
    english: { type: String }, 
    russian: { type: String } 
}); 

Pronoun.relationship({ ref: 'Sentence', path: 'pronouns' }); 

Pronoun.register(); 

Und mein Controller

view.on('init', function (next) { 

    var q = keystone.list('TestGenerator').model.findOne({ 
     slug: locals.filters.test_genetation, 
    }).populate('sentences'); 

    q.exec(function (err, result) { 
     locals.testGenerator = result; 
     locals.current_sentence = result.sentences[0]; 
     locals.data.englishSentence = locals.current_sentence.pronouns; 
     console.log(locals.data.englishSentence); 
     next(err); 
    }); 
}); 

Und "locals.data.englishSentence" return

["5739bd696ef7d78d16e9e0e5","573ac7645e3d7d7210f1c4be"] 

So, wie ich es beheben kann? Verstehe nicht.

Antwort

0

Dies ist mit Mungo, eigentlich nicht Keystone verwandt. Mongoose bietet keine tiefe Population, Sie benötigen ein separates Plugin wie z. mongoose-deep-populate

0

Haben Sie versucht, explizit pronouns in den populate() Aufruf?

var q = keystone.list('TestGenerator').model.findOne({ 
    slug: locals.filters.test_genetation, 
}) 
    .populate('sentences sentences.pronouns') 
    .exec(function (err, result) { 
    ... 
    });