Ahad Yekta Ahad Yekta - 11 months ago 135
MySQL Question

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?

Answer Source

Sequelize should put a TagImage property on each included Tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download