在sails.js中关联模型的Where子句

Where clause on an associated model in sails.js

本文关键字:Where 子句 模型 关联 sails js      更新时间:2023-09-26

Sails.js文档包括一个用户有许多宠物的例子。是否可以使用find()和where()函数来查找名为Bob的用户拥有的所有宠物?我试过这样的东西,但得到TypeError: Cannot read property 'attributes' of undefined

Pet.find().where(owner:{name:{contains:"Bob"}}).populate("owner").exec(console.log);

是否有一个技巧,这是。query()我唯一的选择?

在此查询之前使用populate():

    Pet.find()
    .populate("owner",{where : {name : {'contains' : 'Bob'}}})
    .exec((err,data)=>{
     console.log(data)
     });