You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that there is a bug with Typeorm where updating a FK manually while the relation property is loaded causes multiple assignments to the join column. I.e. eager loaded relations: typeorm/typeorm#2651
I'm not sure if it's a safe solution but I found deleting the property from the instance before calling save does the trick.
I've only tested this on a OneToOne relation so not sure if it's the correct solution.
NB: setting the relation property to null doesn't seem to be enough, and needs to be off the instance.
Resource.ts
publicasyncupdate(pk,params: any={}): Promise<ParamsType>{
params =this.prepareParamsBeforeSave(params);constinstance=awaitthis.model.findOne(pk);if(instance){for(constpinparams){instance[p]=params[p];constproperty=this.property(p);if(property.type()==="reference"){deleteinstance[property.column.relationMetadata.propertyName];}}awaitthis.validate(instance);awaitinstance.save();returninstance;}thrownewError("Instance not found.");}
The text was updated successfully, but these errors were encountered:
It seems that there is a bug with Typeorm where updating a FK manually while the relation property is loaded causes multiple assignments to the join column. I.e. eager loaded relations: typeorm/typeorm#2651
I'm not sure if it's a safe solution but I found deleting the property from the instance before calling save does the trick.
I've only tested this on a OneToOne relation so not sure if it's the correct solution.
NB: setting the relation property to null doesn't seem to be enough, and needs to be off the instance.
Resource.ts
The text was updated successfully, but these errors were encountered: