Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取与模型相关的所有集合记录_Javascript_Mysql_Node.js_Sails.js_Waterline - Fatal编程技术网

Javascript 获取与模型相关的所有集合记录

Javascript 获取与模型相关的所有集合记录,javascript,mysql,node.js,sails.js,waterline,Javascript,Mysql,Node.js,Sails.js,Waterline,及 在控制器中: // Notebook attributes: { // Relations owner: { model: 'User' }, notes: { collection: 'Note', via: 'notebook' } } 很明显,我正在尝试获取与笔记本相关的所有笔记。在调试时,我得到的是Note.find(),然后我甚

在控制器中:

// Notebook
attributes: {
        // Relations
        owner: {
            model: 'User'
        },

        notes: {
            collection: 'Note',
            via: 'notebook'
        }
}
很明显,我正在尝试获取与笔记本相关的所有笔记。在调试时,我得到的是
Note.find()
,然后我甚至没有进入回调,因此我没有得到
Note
的任何结果。
err
为空,因此我不知道是否有问题

我打赌我设置的模型关系是错误的,但从我在教程中读到的内容来看,我认为它是正确的


另外,我在数据库中确实有记录,并且ER关系设置正确,因为插入
注释
记录不会出现问题。

模型关系似乎很好

我认为这个错误是因为在中没有回调参数

请尝试以下方法:

        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.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()
  .where({ notebook: notebook.id })
  .exec(function (err, notes) {
    ...
});