https://grokonez.com/node-js/sequelize-one-to-one-association-nodejs-express-mysql
Sequelize One-To-One association – NodeJS/Express, MySQL
In the post, we got started with Sequelize ORM. Today we’re gonna create Sequelize One-To-One association models with NodeJS/Express, MySQL.
Related posts:
Customer.hasOne(Address)
, we say that the Customer model is the source and the Address model is the target.
We define 2 models:
Customer = sequelize.define('customer', {
/* attributes */
});
Address = sequelize.define('address', {
/* attributes */
});
How to create One-to-One association between them?
-> Sequelize provides 2 ways:
Address.belongsTo(Customer); // Will add a customerId attribute to Address to hold the primary key value for Customer.
More at:
https://grokonez.com/node-js/sequelize-one-to-one-association-nodejs-express-mysql
Sequelize One-To-One association – NodeJS/Express, MySQL
#sequelize #node #express #mysql