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:

Sequelize One-to-One association

Note: When calling a method such as 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:

  • belongsTo

Address.belongsTo(Customer); // Will add a customerId attribute to Address to hold the primary key value for Customer.
  • hasOne

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

Sequelize One-To-One association - NodeJS/Express, MySQL » grokonez
1.50 GEEK