Relate update problems or lack of knowledge

I have a Table with several 1:MANY relationships. I have no problems with the relationships in the Templated generated Browsers, Forms and Reports, so I am sure the the relationships are set up correctly.

But if I try to change on of the key fields in the Table use Relate:FileName.Update() in a process or just write the code, nothing happens with the Child Tables. So there must be something I am missing, but I can not figure it out.

Is there someone out there who can give me some help here?

Using Clarion 11, but have the same problem in both C9 and C10.

Trond

Double check that you have action: cascade on update set.
Also the help also indicates

When a parent file has cascade set to true for its child files, a call to Update will not do the cascade unless the Save method is called prior to changing the value of the linking fields.

I am sure I have cascade set for all the child fields, but I have not called the Save method prior to Update. I knew there were something I was missing, but I am not sure how to call that method. So if someone could give me a tip, I will be grateful.

Trond

On the other hand, in Process Properties I have this choice:

Use RI constraints on action

NOTE: Leaving this unchecked will cause the “Action for
Process” to occur only to the primary file. No cascading
action will occur on secondary files.

I can not understand this in any way other than if I check “Use RI constraints on action” the child records should be updated as well.

Trond

For example:

Access:MyFile.Fetch()
Relate:MyFile.Save()
Change key fields
Relate:MyFile.Update()

in a loop
loop while Access:MyFile.Next() = Level:Benign
Relate:MyFile.Save()
Change key fields
Relate:MyFile.Update()
end

Thanks a lot.
Now it works.
But I still do not understand why this is not included in the Process template as long as I check for “Use RI constraints on action”.

But anyway, now it works and that’s all that matters.

Trond

I’d say it is a bug.

1 Like

Is it a way to use the Save method to copy a record and its relations?

Trond

Interesting, this could be useful to know.

I suspect that the save looks up the previous relations information, which is needed for the relational update.

The relation manager uses a field pairs class to save off the fields that are part of relationships to other tables from current record buffer. Then on the update it compares to see if the linking fields changed. It uses the old value from the field pair class to fetch the related records to the new value.

If you can’t use the Save Method to copy Records with relations, is there another way to use the Relation Manager to copy Records and its relations. Instead of looping through all the child record to change the key element?

There is no built-in way that I’m aware of.
You can do it by deriving the relation manager and writing your own code to walk the relationships. You can use the Update and UpdateSecondary methods as an example of how to do it.
The only issues with this is you need to access the relation ship Queue, Relations.
This is a private property of the RelationManager class.
I just change it to Protected in abfile.inc and then I can do what I want in my own class.

Sorry to say, but this is something I know nothing about. Is it possible to make an example to how to do it.

I have got one record with one relationship witch have 7 relative child records. Today I am looping through all the records and child records with ordinary ADD. It takes time and it is easy to make mistakes.

Maybe a good topic to bring up on a Wednesday ClarionLive webinar.