Hi Wagner,
The following entities allow to save field changes for example LOGIN but changes in fields DEPARTMENT_ID or LANGUAGE_ID are not saved.
[Entity]
[Table('USERS')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TUsers = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FId: Integer;
[Column('LOGIN', [TColumnProp.Required], 200)]
FLogin: string;
[Column('PWD', [], 64)]
FPwd: Nullable<string>;
[Column('FIRSTNAME', [], 100)]
FFirstname: Nullable<string>;
[Column('LASTNAME', [], 150)]
FLastname: Nullable<string>;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('DEPARTMENT_ID', [], 'ID')]
FDepartment_Id: Proxy<TDepartment>;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('LANGUAGE_ID', [], 'ID')]
FLanguage_Id: Proxy<TLanguage>;
function GetDepartment_Id: TDepartment;
procedure SetDepartment_Id(const Value: TDepartment);
function GetLanguage_Id: TLanguage;
procedure SetLanguage_Id(const Value: TLanguage);
What could be the reason?
wlandgraf
(Wagner Landgraf)
June 3, 2025, 3:13pm
2
I don't know, please provide details about what you are doing, how are you trying to change fields, which code you used, etc.
Hi Wagner,
I have created two projects (server, client).
Demo20250604.zip (139.6 KB)
When editing only Firstname field it stores changes in the database. However when Department_ID is changed the changes aren't stored.
In the console log error message 'PUT http://localhost:2001/tms/xdata/Users(1) 500 (Internal Server Error)' appears.
wlandgraf
(Wagner Landgraf)
June 4, 2025, 7:33pm
5
Your demo is actually rather simple thus I assume it's a matter of understanding the concept. Associations are objects, not primitive values.
Department_Id
, for example, is an object representing a department, not exactly the id of department. To update such property you need to ask the server for a full Department object with the new id, and then set the field value as this:
Dataset.FieldByName('Department_Id').Value := NewDepartmentObject;
You can maybe take a look at the demo <xdata>\demos\web\master-detail
which does complex manipulation of associations.
Thanks. Have some more testing to do
1 Like