Page 1 of 1

Same time insert - Master/Detail

Posted: Tue 30 Mar 2010 07:16
by gabrielrcouto
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

Posted: Tue 30 Mar 2010 14:40
by bork
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.