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
export class CreatePriceTypeDto {
@ApiProperty()
@IsNotEmpty()
@IsNumber()
groupId: number;
// .. more attributes
}
export class UpdatePriceTypeDto extends PartialType(CreatePriceTypeDto) {}
Problem
When creating a pricetype everything works as expected, but when updating a pricetype and changing the referenced groupId, nothing happens, the FK groupId is not updated. (Any non-relational column is updated correctly):
You have to create your CreatePriceTypeDto like this:
export class CreatePriceTypeDto {
// ... decorators you need
group: number; // Note that the name of the property is 'group' and not 'groupId'
// .. more properties
}
and then you can create/update your entity with:
{ "group": 3 }
and of course other needed fields.
Explanation
I don't know why - because it's not explained in their docs - but if you have an entity Foo with a property bar: Bar (where Bar is another referenced entity) you can create a CreateFooDto (and it's derived UpdateFooDto) with a property bar: numberand the library will fetch the record from the table Bar using the id you provided in the payload (as in { "bar": 1 }) and "link" the fetched record with the Foo entity you're creating/updating.
Conclusion
Hope I had explained well. It worked for me. Try it and let me know! Cheers!
Hi all,
I have a problem that the library is not updating a foreign key when calling tha API with PATCH.
This is my entity:
This is my referenced group entity:
And my DTOs:
Problem
When creating a
pricetype
everything works as expected, but when updating apricetype
and changing the referencedgroupId
, nothing happens, theFK groupId
is not updated. (Any non-relational column is updated correctly):Result:
groupId
is still the same. Also inside the database.The text was updated successfully, but these errors were encountered: