Quote Originally Posted by fredrik View Post
Quote Originally Posted by John Tuohy View Post
Have you considered making the extensions parent tables so that Customer relates to Customer1, Customer2, etc? If you did that, this would all just magically work. If these are truly 1-1 relationships, it sounds like it would not matter which was the child and which was the parent.

True, that would work, but I can't really change in the db structure (I don't dare to), since I am working on a pretty big/old system, and I'm afraid I will break legacy code.
I was afraid that might be the case. Whatever solution you come up with will end up being some kind of trick. Constraints are not designed to be tested on child records because at the point where the constraint test is applied, the child record has not even been found.

If the program you are writing is stand alone not part of the big/old program you could consider reversing these relationships inside of your program using set_attribute with df_file_related_file and df_file_related_field.

Or (and I hesitate to even suggest this),

I assume that currently you are setting a relates-to constraint in the child and setting the child DD's auto_fill_state to true. That should get you the finding behavior you want (although saving the child probably requires extra code). If this is working, you might try adding a "constrain as" in the parent that calls a function, which manually attempts to find the child record and test if it should be filtered. Something like:
Function TestAddress Returns Boolean
    Boolean bFound
    // see if address exists 
    Clear Address
    Attach Address
    Find ge Address by 1
    Move (Found) to bFound
    If (bFound and Address.Customer_Id=Customer.Customer_Id and Address.City="New York") Begin
        Function_Return True
    Function_Return False

Object oCustomer_DD is a Customer_DataDictionary
    Procedure OnConstrain
         Constrain Customer.Lastname eq "Anderson"
         Constrain Customer as (TestAddress(self))

Object oAddress_DD is a Address_DataDictionary
     Set Constrain_file to Customer.File_number
     Set DDO_Server to oCustomer_DD
     Set Auto_Fill_State to True
     Set pbInheritConstraints to False
This is really pushing the envelope but it may work if used in a very limited fashion. Note that the finding of the child record in the test function does not actually perform the child DD find. If the record is ok, the child DD will do the auto-fill find again (I hope) which will make the child DD buffer correct (I hope). There may be multiple finding of the DD child record, but you probably will not see that. And of course, the test for Address can never be optimized.