hasOne和hasMany一起在2个模型之间关联

时间:2019-07-29 18:28:44

标签: orm sequelize.js

Nodejs 10.15sequelize 5.7.6中,有UserCellphone个模型:

User有一部手机:

{name: STRING,
 cellphone_id: INTEGER}

Cellphone由用户添加:

{number: STRING,
 created_by_id: INTEGER}

associatioon.js中,在hasOnehadMany之间定义了两个关联UserCellphone

Cellphone.hasMany(User, {foreignKey: "cellphone_id"});
User.hasOne(Cellphone, {foreignKey: "created_by_id"});

在两个模型中同时使用hasOnehasMany是否有冲突?或者,我只能与一个hasOnehasMany建立一个关联,而不能同时建立两个关联。

0 个答案:

没有答案
相关问题