获取与模型相关的所有收集logging
// Note model attributes: { // Relations notebook: { model: 'Notebook' }, }
和
// Notebook attributes: { // Relations owner: { model: 'User' }, notes: { collection: 'Note', via: 'notebook' } }
在控制器中:
Notebook.findOne({owner: user.id}, function (err, notebook) { if (err || !notebook) { return res.serverError(err); } // --> until here it goes all fine, finding the Notebook Note.find().where({notebook: notebook.id}, function (err, notes) { if (err || !notes) { return res.serverError(err); } return res.json({notebook: notebook, notes: notes}); }) })
很显然,我正在尝试获取与Notebook相关的所有Notes。 在debugging的时候,我得到的直到Note.find()
,然后我甚至不inputcallback,所以我没有得到任何结果Note
。 err
是空的,所以我不知道是否有错。
我敢打赌,我错误地build立了我的模型关系,但从我在教程中读到的内容来看,这似乎是正确的。
PS我有数据库中的logging,并且ER关系正确设置,因为插入Note
logging没有问题。
模型关系似乎很好。
我认为这个错误来自于where
方法中没有callback参数的事实。
试试这个:
Note .find() .where({ notebook: notebook.id }) .exec(function (err, notes) { ... });