ThinkTeamwork
ThinkTeamwork

Reputation: 594

Why does this query work?

sails.js uses waterline and there is a nice documentation.

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

if i leave out "id: 2" and use just find() instead of findOne() the query still works, but why? find() should return a list so I shouldn't be able to just say user.id in the subquery

how can I access Comment.find({userId: user.id}) if I didn't receive one single record but a list of users?

Upvotes: 3

Views: 350

Answers (1)

ThinkTeamwork
ThinkTeamwork

Reputation: 594

oh ok, I just found the answer

that Comment.find({userId: user.id}) in fact doesn't make sense but it does not make the query fail but is the same as if i would have put

Comment.find({userId: null})

the result is the same, the query will run as if there were no search parameter/filter.

Upvotes: 2

Related Questions