On reversing the master-detail relationship.

From: <dlm_at_hermes.dlogics.com>
Date: 10 Sep 92 12:22:59 CST
Message-ID: <1992Sep10.122259.1310_at_hermes.dlogics.com>

colten_at_cbnewsb.cb.att.com (marc.colten) writes:
> dlm_at_hermes.dlogics.com writes:
>> colten_at_cbnewsb.cb.att.com (marc.colten) writes:
>> > 3) Can you do a query on a detail block and have the relevant
>> > information come up in the master block? [...]
>> >
>> [...] just write triggers that treat
>> KEY-ENTQRY and KEY-EXEQRY in the detail exactly as if they are in the master,
>> but with the block associations reversed.
> If I do a "go_block(master)" and then a query, it wipes out the
> values of the master block and waits for input. I can't find a
> function that takes the current values and runs with them.

        REVERSING THE MASTER-DETAIL RELATIONSHIP. The detail's foreign key is enforced from the master block primary key. The master is generally coded with no key enforcement. So, enforce its primary key from the detail block's foreign key. As long as the detail is cleared prior to querying the master, the master-detail will work; if the master is cleared prior to querying the detail, the detail-master will work. You will have to write the triggers yourself (cannibalize the master-detail procedures).

The scenario will run something like this:

	master	key-entqry	go_block(detail);
				execute_query;  [not enter_query]

	detail	key-entqry	go_block(master);
				execute_query;  [ditto]

The same principle is employed for the case of key-exeqry. This is the simplest method i can think of.

Remember most of all that the detail-master relation makes an end-run around the relational concept of key inheritance.

If you do not query on a foreign key, the rows returned will belong to many masters. the behavior of the form is predictable: only one master will be returned since its primary key can be enforced from only one detail row. This presents a very misleading view of the relationship. If you solve this problem by querying only on the detail's foreign key, you will have accomplished little, since this action is the same as querying on the master's primary key.

In short, although you can jury-rig the detail-master relationship, it is mostly pointless to do so. Net flames to /dev/nul or NLA0: please.

Dave Mausner, Senior Consultant / Datalogics Inc / Chicago IL / 312-266-4450
dlm_at_dlogics.com                                 Motto: Just show me the code
Received on Thu Sep 10 1992 - 20:22:59 CEST

Original text of this message