Subject Re: GSG030. Generators and Master/Detail tables.
Author Marco Menardi
IBO is fantastic on this respect too.
If you use the IB_Query "GeneratorLinks", the specified generator is called as soon as the master record is inserted, so the detail records already have the master key.
If you want to post-pone the generation of the master key, use the Query.BeforePost event and, if the key is empty, fill it in the way you like (calling a SP, or with the query.Gen_ID() method).
I'm not an expert of the inner work of the components, but it works perfectly.
As far as I've understood, when a detail record is inserted and the master record is a new one, a sort of "dummy" post of the master is performed, so the .BeforePost of the master is triggered. This is also necessary bacause you could have defined contraints at the database server level between master/detail table (preventing detail rows to exist without a master one), so the server needs the master row first.
Isn't this magic? ;)
regards
Marco Menardi

--- In IBObjects@y..., Raymond Kennington <raymondk@c...> wrote:
> If the master table has a generator for its primary key field how is a child record going
> to know what its reference field value is to be if the generated key is calculated in an
> insert trigger?
>
> What is the IBObjects way of handling generators when inserting records into both a master
> grid and a detail grid?
> --
> Raymond Kennington
> Programming Solutions
> W2W Team B