【发布时间】:2015-09-01 11:27:55
【问题描述】:
// 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});
})
})
很明显,我正在尝试获取与笔记本相关的所有笔记。调试时,我得到了Note.find(),然后我什至没有输入回调,所以我没有得到Note的任何结果。 err 为空,所以我不知道是否有问题。
我打赌我错误地设置了模型关系,但对我来说似乎是正确的,就像我在教程中读到的那样。
附:我确实在数据库中有记录,并且那里的 ER 关系设置正确,因为插入 Note 记录没有问题。
【问题讨论】:
标签: javascript mysql node.js sails.js waterline