You are not logged in.
I define two class as follow:
TRoute = class(TSQLRecord)
private
fRouteNumber: string;
...
published
property routeNumber: string read fRouteNumber write fRouteNumber;
...
end;
TSchedule = class(TSQLRecord)
private
fRoute: TRoute;
...
published
property route: TRoute read fRoute write fRoute;
...
end;
TSchedule include TRoute's ID, now I want to save a TSchedule instance, and it's routeId is correct:
procedure TMyForm.btnOKClick(Sender: TObject);
var
schedule: TSchedule;
Id: Integer;
begin
schedule := TSchedule.Create(Client, StrToInt(txtId.Text));
try
schedule.route := TRoute.Create(Client, fRouteId);
...
Id := Client.Add(schedule, true);
finally
schedule.Free;
end;
end;
When the Client.Add execute, the database table has the route id 24670096, not the correct value 2, what wrong with me?
Last edited by oraclei (2016-07-27 06:48:56)
Offline
It might not obvious, but the third parameter called "ForceId" must be "True", in order to save to DB using the ID you assigned.
Last edited by edwinsn (2016-07-27 07:05:28)
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
I use Client.Add(schedule,true, true); but the route id still incorrect. and I could not find the TSQLHttpClientWinHTTP.Add API doucment online or in synopse's PDF.
Offline
In Delphi debug state, I can find out:
schedule -> fRoute -> TSQLRecord -> fID = 2
And the Id = 2 TRoute record actually in table bt_route.
Offline
@edwinsn
I find out the docs: TSQLRest.Add , but the ForceID is not for associated instance,but the main instance, as the doc said:
if ForceID is true, client sends the Value.ID field to use this ID for adding the record (instead of a database-generated ID)
Offline
I found the result in
https://tamingthemormot.wordpress.com/2 … tionships/
thanks Taming the mORMot!
Offline