Answer the question
In order to leave comments, you need to log in
How to join in Sequelize using id array?
Hello, there are 2 tables:
With ads
const ads = sequelize.define('ads', {
user_panel_id: {
type: Sequelize.INTEGER,
allowNull: false
},
name: {
type: Sequelize.STRING,
allowNull: false
},
categories: {
type: Sequelize.ARRAY(Sequelize.INTEGER),
allowNull: false
},
}, {
charset: 'utf8',
collate: 'utf8_unicode_ci',
timestamps: true,
})
const categories = sequelize.define('categories', {
name: {
type: Sequelize.STRING,
allowNull: false
},
}, {
charset: 'utf8',
collate: 'utf8_unicode_ci',
timestamps: true
})
models.ads
.findOne({
where: {
id: 1
},
include: [{
model: models.categories
}],
})
.then(data => {
console.log(data)
})
.catch(error => {
console.error(error)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question