Re: Non-skipping IDs with Master-Detail




Thanks Vitali!

How do I make OrderID of type GUID? I saw some sample code but
I haven't figured out how it works. It seems like just a large
field to hold unique values. How does this help in keeping
Master-Detail relationship? Isn't it enough to just use normal
integer fields (not IDENTITY) for IDs and prevent it from
duplicating?

By the way, I still don't understand why manually setting
detail's FK field to a locally generated key doesn't work.
When posting the detail table (not UpdateBatch), the record
simply disappears! I don't want to post the master table yet
because I have to continue in Insert state.

*** Master's OnNewRecord:

datasetMasterID.Value := GetNextKey();
(selects next key from a key table and updates key table +1)

*** Detail's OnNewRecord:

datasetDetailForeignID.Value := datasetMasterID.Value;

*** Detail's BeforePost:

ShowMessage(IntToStr(datasetDetailForeignKeyID.Value));
(Shows the correct ID)

*** Detail's AfterPost:

ShowMessage(IntToStr(datasetDetailForeignKeyID.Value));
(Shows 0 !!!!!!!)

Why??????



"Vitali Kalinin" <vitkalinin@xxxxxxxxx> wrote:
>I am suggesting you to reconsider DB design like this:
>
>1. Make OrderNo autoinc field but not primary key
>
>2. Append OrderID field of type GUID and make it a primary key
>
>3. Add FK OrderID to OrderDetail and remove old FK on OrderNo.
>
>
>
>This way you will be able generate OrderID values on the client side without
>bothering server and keep proper Master-Detail relationship. As for non
>skipping id it will be handled to you by the auto increment OrderNo field.
>
>
>
>Regards,
>
>Vitali
>
>

.