简体   繁体   English

如何在多对多关系中获取中间表的数据

[英]How to get data of the middle table in many to many relationship in sequelize

I have a question in sequelize orm. 我有一个问题要整理orm。 There is Many to Many relationship between tables , through a middle table. 通过中间表,表之间存在多对多关系。

  const Tag = sequelize.define('tag', { name: Sequelize.STRING, type: Sequelize.CHAR }) const Image = sequelize.define('image', { thumb: Sequelize.STRING, original: Sequelize.STRING, status: Sequelize.INTEGER, width: Sequelize.INTEGER, height: Sequelize.INTEGER, fileSize: Sequelize.STRING, }) const TagImages = sequelize.define('TagImages', { value: Sequelize.STRING, }) 

When I find an image by Id , I get all tags well by include, But I cannot get the value column in tagImages table. 当我通过Id查找图像时,通过include可以很好地获得所有标签,但是无法获得tagImages表中的value列。

This is my query statement: 这是我的查询语句:

 Image.findById(imageId,{ include: [Tag] }) .then(image => { console.log(image); }) 

and there is no column of value in my console.log. 而且在console.log中没有列。 How should I get it? 我该怎么办?

Sequelize应该在每个包含的Tag上放置一个TagImage属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM