I have master detail
CachedUpdates
for the master true
CachedUpdates
for the detail true
DetailCascde
for the detail true
The master deals with one record:
select * from orders where order_id=:order
First I pass -1 as dummy parameter to get an empty master record:
orders.Close;
orders.Params[0].AsInteger := -1;
orders.Open;
Than I fill the order id with -1 to build the relationship between the master and the detail:
orders.Append;
orders.Fields[0].AsInteger := -1;
orders.Post;
I insert into the detail successfully with Append
and Post
The problem is in the Firebird database I have this line on before insert trigger for the master
new.order_id = coalesce((select max(order_id) from orders) + 1, 1);
I ApplyUpdates
Orders.ApplyUpdates(-1);
dOrder.ApplyUpdates(-1);
So when I ApplyUpdates for the master, the detail won't apply because the master id is altered by the server.
How to solve such scenario?