gpt4 book ai didi

mysql - 属于或有一个 Sequelize

转载 作者:行者123 更新时间:2023-11-29 09:51:57 24 4
gpt4 key购买 nike

我有 2 个表:Users 和 Profile_Education。用户数据来自 auth0/login 表单,Profile_Education 来自使用 node.js/express 的 API。我希望 Profile_education 有一个外键来跟踪数据并根据登录的用户将其显示在配置文件中。

在我的项目中,我应该使用belongsTo还是hasOne,还是应该同时使用两者?

最佳答案

您可以同时使用它们,但在合适的地方使用它,按照 DOC :

When information about association is present in source model we can use belongsTo. In this case Player is suitable for belongsTo because it has teamId column.

Player.belongsTo(Team)  // `teamId` will be added on Player / Source model

When information about association is present in target model we can use hasOne. In this case Coach is suitable for hasOne because Team model store information about its Coach as coachId field.

Coach.hasOne(Team)  // `coachId` will be added on Team / Target model

我想这会消除你所有的疑虑,

关于mysql - 属于或有一个 Sequelize ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54636604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com