Answer the question
In order to leave comments, you need to log in
How to select in Sequelize associations not by id, but by another field?
Hello!
Please tell me, in Sequelize, the connection with another table goes through id, i.e.
//модель Status
Status.associate = function(models) {
models.Status.hasMany(models.Orders,{
foreignKey: 'status'
})
};
//модель Orders
Orders.associate = function(models) {
models.Orders.belongsTo(models.Status,{
foreignKey: 'status'
})
};
...
LEFT OUTER JOIN `status` AS `Status`
ON `orders`.`status` = `status`.`id`
...
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