简体   繁体   中英

mysql sequelize.js how to link two tables

This is my use case.

  1. I have two tables audits and user
  2. Whatever the user has done to the system is recorded in the audits table.
  3. It means user has many audit records.

If I do

Audits.belongsTo(User)

User model's primary key will be added to the Audits model as the foreign key.

But that foreign key value will be repeated since User has many Audits .

For that reason do I need to add some relationship to the User model?

But that foreign key value will be repeated since User has many Audits.

That is how it should work , There is nothing wrong in it , that's the standard way of RDBMS.

Audits.belongsTo(User)

So go ahead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM