Sails.js query on an associated value

为君一笑 提交于 2019-11-30 05:09:42

It's not 100% clear what you're trying to do here. If your goal is to filter the categories that get populated on the Post, you can do:

Post.find()
    .populate("category", {where: { category: category_id }})
    .exec( ... )

If you want to only retrieve Posts with a certain category, you would do:

Category.findOne(category_id)
        .populate("posts")
        .exec(function(e, c) {console.log(c.posts);})

Original post was too soon

Following works for me (sails 0.12) with population:

Post.find({category: category_id})
    .populate("category")
    .exec( ... )

But I am still puzzled who to search in a subquery any other attribute than id..

Edit2: Seems like deep query is not yet supported: https://github.com/balderdashy/waterline/issues/266

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!