intersystems-cacheintersystems

Saving Value into Relation Column


Im new to Caché and got a problem: I want to save a value into the Relation Column in Class B via Class A and thats not working ...

Currently I am doing it like this

In Class A:

set Obj1 = ##class(This.Is.Class.B).%New() 
set Obj1.PID = ..id
set Obj1.PName = ..name
set status = Obj1.%Save(0)

Its saving the PName into Class B but not the PID which I defined as Relationship [One to Many] in Class B


Solution

  • Connection objects in a relationship are bidirectional. But in any case, you can't just set id to such property. You should set object or insert object depending on which side you want to do it. In your case you do it like

    do obj1.PIDSetObjectId(..id)
    

    To get more information read the documentation.