gpt4 book ai didi

Sails.js 查询水线关联

转载 作者:行者123 更新时间:2023-12-03 06:33:21 24 4
gpt4 key购买 nike

在 sails.js 中,我有一个 Post 模型,与另一个名为“tag”的模型具有多对多关联

帖子模型

module.exports = {

attributes: {
title: 'string',
content: 'string',
coverImage: 'string',
owner: {
model: 'user'
},
tags: {
collection: 'ContentTag',
via: 'posts',
dominant: true // ---
}
}

};

标签模型

module.exports = {

attributes: {
name: 'string',
posts: {
collection: 'post',
via: 'tags'
}
}
};

现在我想获取具有相同标签的相关帖子。我尝试使用 .populate('tags') 和 .populate('tags',{name: ['tag1','tag2']) 但我不知道如何解决。

最佳答案

您可以反转查询

Tags.find({name:['tag1','tag2']}).populate('posts')

关于Sails.js 查询水线关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30262246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com