Master-detail - INSERT

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sean

Master-detail - INSERT

Post by sean » Sun 20 Mar 2005 12:06

Hi,

I have a master & 5 details tables. The Detail tables have MasterSource, MasterFields, DetailFields set. When I browse the master, the cursors on the details follow just fine.

When I do a Table.Insert though, an entry is only inserted into the master, any OnNewRecord is is only called for the Master.

Why? Should the INSERT of the detail tables not be automatic?

Thanks in advance,

Sean Boran

sean

Post by sean » Sun 20 Mar 2005 12:20

I also wished to add, that I do

ShowMessage('Insert');
dmJOB.taJOBCARD.Insert;
ShowMessage('post');
dmJOB.taJOBCARD.Post;

but that I don't see the INSERT in the DBmonitor, nor is a row inserted into the master table (taJOBCARD)

In dmJOB.taJOBCARDNewRecord I have
with DataSet do begin
FieldByName('jcard_no').value:=current_job;
ShowMessage('taJOBCARDNewRecord ' +FieldByName('jcard_no').AsString);
end;

And I do see the ShowMessage with the currect value for the Index.

What am I doing wrong?

Sean

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 21 Mar 2005 09:25

> Why? Should the INSERT of the detail tables not be automatic?

Yes, according to Master-Detail ideology insertion a record in Master is a little related with insertion a record in Detail. For Detail you also need to execute Insert..Post manually.

Sean

Post by Sean » Mon 21 Mar 2005 09:39

> Yes, according to Master-Detail ideology insertion a record in Master is a little related with insertion a record in Detail. For Detail you also need to execute Insert..Post manually.

Hmm. And to set the value of the primary index after insert, I should be able to do it in the OnNewRecord event? Because in the example I list, the new row is NOT posted to the master (leaving aside the detail tables).

with DataSet do begin
FieldByName('jcard_no').value:=current_job;
ShowMessage('taJOBCARDNewRecord ' +FieldByName('jcard_no').AsString);
end;

I get the showmessage, but no row appears in the table.

Post Reply