3

sails.js 使用水线并且有一个很好的文档

User.findOne()
.where({ id: 2 })
.then(function(user){
    var comments = Comment.find({userId: user.id}).then(function(comments){
        return comments;

如果我忽略"id: 2"并只使用 find() 而不是findOne()查询仍然有效,但为什么呢?find()应该返回一个列表,所以我不能只在子查询中说 user.id

Comment.find({userId: user.id})如果我没有收到一条记录而是一个用户列表,我该如何访问?

4

1 回答 1

2

哦,好的,我刚刚找到了答案

Comment.find({userId: user.id})实际上没有意义,但它不会使查询失败,但就像我本来放的一样

Comment.find({userId: null})

结果是一样的,查询将像没有搜索参数/过滤器一样运行。

于 2013-12-16T13:05:36.673 回答