patch is not applied at the other levels

I am changing the Fd2 property of the Table1 association that is in the Table2 entity.
the problem is that it's updating all the properties of Table1.
the Fd21 is getting empty because it is not in the json.

Json Post
{
"Fd21": "teste 21",
"Fd22": "teste 22",
"Table1": {
"Fd1": "teste 1",
"Fd2": "teste 2"
}
}

Json patch
{
"Fd21": "teste 211",
"Table1": {
"Fd2": "teste 22"
}
}

[Entity, Automapping]
TTable1 = class
private
FId: int64;
FFd1: string;
FFd2: string;
public
property Id: int64 read FId write FId;
property Fd1: string read FFd1 write FFd1;
property Fd2: string read FFd2 write FFd2;
end;

[Entity, Automapping]
TTable2 = class
private
FId: int64;
FFd21: string;
FFd22: string;

[Association([TAssociationProp.Lazy], CascadeTypeAllButRemove)]
FTable1: Proxy<TTable1>;

function GetTable1: TTable1;
procedure SetTable1(const Value: TTable1);

public
property Id: int64 read FId write FId;
property Fd21: string read FFd21 write FFd21;
property Fd22: string read FFd22 write FFd22;
property Table1: TTable1 read GetTable1 write SetTable1;
end;

Can you please give more details about the operation you are doing? How are you performing such patch? Using TXDataClient? Using a different library? Using a tool?

Remember that you must use HTTP PATCH method (not PUT) to achieve what you want. When using PUT, you have to send the whole object.

I'm using insomnia as the frontend and aurelius and xdata on the backend.

So then can you please give more details? What are the details of your request in insomnia?

what detail do you need?



Sorry, I got confused with the similar names. You are referring to the Fd2 property, not the FFd2.

Yes, PATCH operations only "patch" the properties of the main object. Inline objects are updated as a whole, the properties are not "patched".

The documentation recommends:

The entity must not contain associated entities as inline content. If values for navigation properties should be specified, then they must be represented as an association reference. For single-valued (single entity) navigation properties, this will update the relationship (set the value of property to reference the associated object represented in the association reference).

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.