0

I'm trying to have a collection class similar to %Library.RelationshipObject in that it manages saving and deleting the objects in the collection. I'd like the flexibility to do this with my own objects, so I don't want to use the relationship keywords or subclass the %Library.RelationshipObject class.

I can't call my own Save() and Delete() methods on the parent object holding this collection, and have it call my collection class (and just have my classes call Save() instead of %Save()) because swizzling may call %Save() directly.

What I'm trying is to use the %OnAddToSaveSet method on my collection class and on my parent classes. The parent classes put my collection class in the save set when the parent classes %OnAddToSaveSet is called. The collection class calls saves and deletes the items in the collection as appropriate.

It seems that the right way to do this in my collection class is to Add the collection items to be saved into the save set using their %OnAddToSaveSet() method, and to delete the items that need deleting by using %Delete(), then setting

%objTX(5,+oref) = oref

for each of the deleted items.

Is this the right way to do it? Have I missed anything? Is this supported? Can I change anything unsupported to something better supported?

psr
  • 2,870
  • 18
  • 22
  • Well, you can override a lot of things, or even write your own indexes using globals, use the Globals database from Java, ... Caché ObjectScript doesn't have the power of Java when it comes to interfaces and stuff, you will probably have to find a way using those `%On***()` methods, or write your own code for saving, loading and stuff, and ignore the `%Persistent` class completely. – Vlasec Jul 16 '13 at 10:55

2 Answers2

1

I believe your code in %OnAddToSaveSet() should be calling yourObject.%AddToSaveSet() and yourObject.%RemoveFromSaveSet() to control which objects should (or should not) be included in the current save operation. I believe you should also be able to call %Delete() on objects that are no longer in the collection, if that's the behaviour you want to implement.

DdP
  • 438
  • 2
  • 6
0

Instead of directly using %Library.RelationshipObject, better to use RelationShips
So you get more possibilities, for control parents and children objects.

DAiMor
  • 3,185
  • 16
  • 24
  • That is specifically what I am trying *not* to do. Relationships are implemented with %RelationshipObject. I want to be able to write my own collection class. – psr Jul 09 '13 at 16:49
  • Sorry that wasn't clear in my question - it isn't obvious that Relationships are implemented with %RelationshipObject and I forgot I might need to mention that. – psr Jul 09 '13 at 17:59