The Master/Detail Behavior

隐身守侯 提交于 2020-01-15 09:57:08

问题


I use Delphi 7 + Zeos + MySQL, and I got a problem when I try to post Master table, the Details datasets are posted first, raising a referencial integrity exception in data base, 'couse details tables needs the ID of the Master table.

Can I revert this behavior? Can I persist the master table before the details?


回答1:


I think it's just the way TDataSet work. If you have unposted detail records, master.Post forces them to Post if I remember correctly.

So I am guessing you have something like:

tblMaster.Insert;
tblMaster.FieldByName('foo').Value := 'foo';
tblDetail.Insert;
tblDetail.FieldByName('bar').Value := 'bar';
tblMaster.Post; // error!
tblDetail.Post;

You should be able to work around this by posting master first:

tblMaster.Insert;
tblMaster.FieldByName('foo').Value := 'foo';
tblMaster.Post;
tblDetail.Insert;
tblDetail.FieldByName('bar').Value := 'bar';
tblDetail.Post;


来源:https://stackoverflow.com/questions/827319/the-master-detail-behavior

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!