Subject Re: Inserting into detail table of Master/Detail
Author radevojvodic
You can try 2 different approaches:

First, if your sql looks like you wrote then possible solution coul be
to put KeyRelation parameter in query editor (it should be the name of
table that you trying to insert to)

Second, You could rewrite your query to something like this

SELECT S.IDNUM
, S.MIXNUM
, (Select B1.NAME From BULK_SEED B1
Where B1.ITEMNUM = S.MIXNUM) AS MIX_NAME
, S.SEEDNUM
, (Select B2.NAME From BULK_SEED B2
Where B2.ITEMNUM = S.MIXNUM) AS SEED_NAME
, S.MIX_PERCENT
, S.COLOR
FROM SEED_MIXTURES S

and it should be OK.
Test enviroment:

You could make form with two grids, one for master and one for detail.
All fields visible, queries RequestLive=True. Then when you insert
into detail you should automaticaly see the master parameter entered.

Rade

--- In IBObjects@yahoogroups.com, "Rick Roen" <rick@l...> wrote:
>
> IBO 4.5B D7 XP sp2
>
> I have a master/detail relationship setup between two tables and
> need to insert new records into the detail table. When I am using
> the query form from the IBO_Query (when you double click on the
> component) I enter a master parameter, open the table, get the
> expected records, but the "+" key from the menu is never enabled so
> I can't insert. I can edit ok from here.
>
> The same happens when I run my program, however I get a Foreign Key
> Violation when I try to post. I have examined the values in the
> BeforePost event and they all look ok.
>
> If I remove the master/detail relationship I can post new records.
>
> Any ideas?
>
> below is the detailed info.
>
> Rick
>
> DETAIL TABLE:
>
> SELECT IDNUM
> , MIXNUM
> , B1.NAME MIX_NAME
> , SEEDNUM
> , B2.NAME SEED_NAME
> , MIX_PERCENT
> , COLOR
> FROM SEED_MIXTURES S
> JOIN BULK_SEED B1 ON B1.ITEMNUM = S.MIXNUM
> JOIN BULK_SEED B2 ON B2.ITEMNUM = S.SEEDNUM
>
> Master source: BULK_SEED
> Master links: SEED_MIXTURES.MIXNUM=ITEMNUM
>
> Insert SQL:
>
> INSERT INTO SEED_MIXTURES(
> IDNUM, /*PK*/
> MIXNUM,
> SEEDNUM,
> MIX_PERCENT,
> COLOR)
> VALUES (
> :IDNUM,
> :MIXNUM,
> :SEEDNUM,
> :MIX_PERCENT,
> :COLOR)
>
> Table DDL
>
> RECREATE TABLE SEED_MIXTURES
> (
> IDNUM INTEGER NOT NULL,
> MIXNUM INTEGER NOT NULL,
> SEEDNUM INTEGER NOT NULL,
> MIX_PERCENT SMALLINT DEFAULT 0 NOT NULL,
> COLOR VARCHAR( 25),
> CONSTRAINT PK_SEED_MIXTURES PRIMARY KEY (IDNUM)
> );
>