Subject Re: [IBO] Nested KeyLinks and MasterLinks
Author Helen Borrie (TeamIBO)
At 02:17 PM 05-07-02 -0300, you wrote:
>Delphi6/IBO4.2HC/FB
>
>Hi all!! Well, I´m having some problems with keylinks.

1. You cannot have both KeyLinks and MasterLinks relationships on a single
dataset. If you need to do both, then you need a separate query for each
relationship.

2. Each KeyLinks specified needs a KeySource.

3. Each MasterLinks specified needs a MasterSource.

Continued below...

>A have some tables
>
>
>[Clientes]
>ID_CLI
>RAZAO
>...
>
>[Produtos]
>ID_PROD
>...
>DESC_PROD
>...
>
>[Pedidos]
>ID_PED
>ID_CLI
>....
>
>[Itens_Ped]
>ID_PED
>ID_PROD
>....
>
>[Nfisc]
>ID_NOTA
>NUM_NOTA
>...
>NOTA_MAE
>...
>ID_CLI
>...
>ID_PED
>
>[Itens_Nfisc]
>ID_NOTA
>ID_PROD
>DESC_ITEM
>...
>
>I would like to do this relationship:
>
>[Itens_Nfisc]
> MasterLinks = ITENS_NFISC.ID_NOTA=NFISC.ID_NOTA
>
>[Clientes]
> KeyLinks = CLIENTES.ID_CLI=NFISC.ID_CLI
>
>[Pedidos]
> KeyLinks = PEDIDOS.ID_PED=NFISC.ID_PED
> MasterLinks = PEDIDOS.ID_CLI=CLIENTES.ID_CLI

This is not possible. Add another query for the second relationship.

>[Itens_Pedido]
> MasteLinks = ITENS_PEDIDO.ID_PED=NFISC.ID_PED
> KeyLinks = ITENS_PEDIDO.ID_PROD = ITENS_NFISC.ID_PROD
> ITENS_PEDIDO.ID_PED = ???

This is not possible. Add another query for the second
relationship. Also, to form complex key relationships you must have
linking columns in both tables.

>At this point start the problem.
>A wrote the SQL sentence in a IB_Query that access Itens_Nfisc
>
> Select N.ID_PED, I.*
> From Nfisc N, Itens_Nfisc I
> Where I.ID_NOTA = N.ID_NOTA

If you use this syntax for your JOIN, you must specify JoinLinks. You can
improve this query and avoid JoinLinks by changing your statement to

Select N.ID_PED, I.*
From Nfisc N
Join Itens_Nfisc I
on I.ID_NOTA = N.ID_NOTA

Also, I *strongly* recommend that you specify the columns from Itens_Nfisc
explicitly. Do not use * in joins. Specify every column and, if you are
going to display the output in a grid, specify the columns in the
left-to-right order that you want for the grid columns.

> KeyRelation=Itens_Nfisc
>
>And set the KeyLinks of Itens_Pedido
> KeyLinks = ITENS_PEDIDO.ID_PROD = ITENS_NFISC.ID_PROD
> ITENS_PEDIDO.ID_PED = NFISC.ID_PED

You will need to define Keylinks for the joined query, that are NOT linked
to another dataset. This is a simple list (with no linking "=") which
defines a "primary key" for the joined dataset. For example, the Keylinks
entry would look something like this:

Nfisc.ID_NOTA
Nfisc.ID_PED
Itens_Nfisc.SomeColumn
Itens_Nfisc.SomeOtherColumn
...

(Whatever it takes to get a unique key...)

>But it doesn´t works fine, the TIB_LookupCombo that access the IB_Query of
>Itens_Pedido doesn´t scrolls!!
>
>I´ve created a View for the Itens_Nfisc that returns the Field
>ID_PED within.
>
>But it the problem still remains!!

You have some complex relationships here. To begin with, you need to get
it clear how each of these types of relationship works Some of the
"Working with..." tech info sheets on the website should help to explain this.

May I suggest that, before you begin doing something as complex as this,
you experiment with each of these relationship types, in your own sample
app, and watch their activity in an IB_Monitor.


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com