Same time insert - Master/Detail

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gabrielrcouto
Posts: 1
Joined: Tue 30 Mar 2010 06:58

Same time insert - Master/Detail

Post by gabrielrcouto » Tue 30 Mar 2010 07:16

Hello,

I have two tables, employe and phone.

Employe
------------
idemploye (autoinc INT)
name (VARCHAR 50)

Phone
------------
idphone (autoinc INT)
idemploye (INT) <-- Foreign key
number (VARCHAR 20)

I linked two TUniQuery components using the MasterSource and MasterFields properties.

My problem is: The user need to write the name of the new Employe, and, before insert it (post), insert the phones for the employe. After it, save all.

Well, I tried to do it, but, because the user don't post the employe, the "idemploye" field is empty (it's a autoinc field, generated by the DB after the post action), and I can't insert a phone registry without the "idemploye" foreign key.

How can I solve this problem? Using temporary "idemploye"?

Thanks for helping and sorry for my english.
Gabriel

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Tue 30 Mar 2010 14:40

Hello,

I can propose two ways:

1. Disable adding phones if employee hasn't been saved.

2. Save phones to virtual memory table or other structure in the memory. And save phones to DB after employee has been saved only.

Post Reply