[英]js sequelize nest queries / loop through results
I have a first query where I get a list of objects looking like this: 我有第一个查询,在这里我得到的对象列表如下所示:
{
id
idmarker
idcategory
}
MarkerCategories.findAll({where: {idmarker: data.dataValues.id}})
This would get me a resultset with the categoryIds belonging to the provided marker id. 这将给我一个结果集,该结果集具有属于提供的标记ID的categoryIds。 How can I save the id properties of the resultset into an array named ids so I can run the following query to get the actual Category details: 我如何将结果集的id属性保存到名为ids的数组中,以便可以运行以下查询以获取实际的Category详细信息:
Categories.findAll({where: {id: { $in: ids}}});
If you've already defined association between Categories
and Markers
models, you can just do the following: 如果您已经定义了Categories
和Markers
模型之间的关联,则可以执行以下操作:
Markers.findAll({where: { id: markerId }, include: [ Categories ]})
that will return a Marker with a related Categories 这将返回带有相关类别的标记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.