Skip to content

Commit ee25f33

Browse files
Rotorsoftrotorsoft
authored andcommitted
fix one to one util (#8494)
Co-authored-by: rotorsoft <rotorsoft@outlook.com>
1 parent 1350234 commit ee25f33

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

libs/model/src/models/utils.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@ export function oneToOne<Source extends State, Target extends State>(
4444
const foreignKey = options?.foreignKey ?? getDefaultFK(this, target);
4545

4646
// sequelize is not creating fk when fk = pk
47-
foreignKey === target.primaryKeyAttribute
48-
? mapFk(
49-
target,
50-
this,
51-
{ primaryKey: [this.primaryKeyAttribute], foreignKey: [foreignKey] },
52-
{
53-
onUpdate: options?.onUpdate ?? 'NO ACTION',
54-
onDelete: options?.onDelete ?? 'NO ACTION',
55-
},
56-
)
57-
: target.belongsTo(this, {
58-
foreignKey,
59-
as: options?.as,
47+
if (foreignKey === target.primaryKeyAttribute)
48+
mapFk(
49+
target,
50+
this,
51+
{ primaryKey: [this.primaryKeyAttribute], foreignKey: [foreignKey] },
52+
{
6053
onUpdate: options?.onUpdate ?? 'NO ACTION',
6154
onDelete: options?.onDelete ?? 'NO ACTION',
62-
});
55+
},
56+
);
57+
58+
target.belongsTo(this, {
59+
foreignKey,
60+
as: options?.as,
61+
onUpdate: options?.onUpdate ?? 'NO ACTION',
62+
onDelete: options?.onDelete ?? 'NO ACTION',
63+
});
6364

6465
options?.targeyKey &&
6566
this.belongsTo(target, {

0 commit comments

Comments
 (0)