I have 2 tables.
Booking.
- id = integer (default from sequelize)
- id_booking = string
Customer.
- id = integer (default from sequelize)
- id_booking = string
- agent = string
I create id_booking in Booking table, because I want to create unique ID, isnt like 'id' from sequelize just integer.
How can I get customer from Booking table, with hasmany relation? note : the foreign key isnt id (from sequelize) but id_booking(string, unique).
My Controller
enter code here
db.Booking.findAll({
include: [{
model: db.Customer
}]
})
My Model
module.exports = (sequelize, DataTypes) => {
const Booking = sequelize.define('Booking', {
id_booking: DataTypes.STRING,
agent:DataTypes.STRING,
}, {});
Booking.associate = function(models) {
Booking.hasMany(models.Customer, { foreignKey: 'id_booking'})
};
return Booking;
};
Thank you so much.