简体   繁体   中英

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

I have a question in sequelize 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.

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. How should I get it?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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