Question
· May 16, 2017

Constructing a clone on Parent/Children

Hey guys,

 

I'm working with an EnsLib.XML.X12.Document object which consists of a parent object along with multiple children.

When using the following code, my sent object is losing all references to its children.  I've played with the deep parameter and nothing is working to automatically clone the objects children(group docs ref)along with itself.  (Even though the documentation states that it should..)

objectClone = object.%ConstructClone()

d ..sendRequestAsync("Destination",objectClone)

Any insight would be really helpful.

Thanks!

Mitch

Discussion (1)0
Log in or sign up to continue

Refine your version $zv. Perhaps in older versions there were bugs that were then fixed.

Simple test:

Class my.children Extends %Persistent
{

Property p1;

Relationship parent As my.parent [ Cardinality = parent, Inverse = children ];

Method %OnConstructClone(
  object As %RegisteredObject,
  deep As %Boolean = 0,
  ByRef cloned As %String) As %Status [ Private, ServerOnly = 1 ]
{
  i%p1 = object.p1 _ " cloned"
  $$$OK
}
}

Class my.parent Extends %Persistent
{

Property p1;

Relationship children As my.children [ Cardinality = children, Inverse = parent ];

ClassMethod Fill()
{
  ;d ##class(my.parent).Fill()
  
  ..%KillExtent()
  
  i = 1:1:3 {
    = ..%New()
    p.p1 = "parent["_i_"]"
    j = 1:1:2 {
      = ##class(my.children).%New()
      c.p1 = $$$FormatText("children[%1,%2]",i,j)
      p.children.Insert(c)
    }
    p.%Save()
  }
  zw ^my.parentD
  !,"_______",!!
  
  i = 1,3 ..%OpenId(i).%ConstructClone($$$YES).%Save()

  ; or so - the result is the same
  ; f i = 1,3 d ..%OpenId(i).%ConstructClone($$$NO).%Save()

  zw ^my.parentD
}

Method %OnConstructClone(
  object As %RegisteredObject,
  deep As %Boolean = 0,
  ByRef cloned As %String) As %Status [ Private, ServerOnly = 1 ]
{
  i%p1 = object.p1 _ " cloned"
  $$$OK
}
}


USER>$zv
Cache for Windows (x86-64) 2017.2 (Build 672U) Wed May 10 2017 20:43:42 EDT
USER>##class(my.parent).Fill()
^my.parentD=3
^my.parentD(1)=$lb("","parent[1]")
^my.parentD(1,"children",1)=$lb("","children[1,1]")
^my.parentD(1,"children",2)=$lb("","children[1,2]")
^my.parentD(2)=$lb("","parent[2]")
^my.parentD(2,"children",3)=$lb("","children[2,2]")
^my.parentD(2,"children",4)=$lb("","children[2,1]")
^my.parentD(3)=$lb("","parent[3]")
^my.parentD(3,"children",5)=$lb("","children[3,2]")
^my.parentD(3,"children",6)=$lb("","children[3,1]")
 
_______
 
^my.parentD=5
^my.parentD(1)=$lb("","parent[1]")
^my.parentD(1,"children",1)=$lb("","children[1,1]")
^my.parentD(1,"children",2)=$lb("","children[1,2]")
^my.parentD(2)=$lb("","parent[2]")
^my.parentD(2,"children",3)=$lb("","children[2,2]")
^my.parentD(2,"children",4)=$lb("","children[2,1]")
^my.parentD(3)=$lb("","parent[3]")
^my.parentD(3,"children",5)=$lb("","children[3,2]")
^my.parentD(3,"children",6)=$lb("","children[3,1]")
^my.parentD(4)=$lb("","parent[1] cloned")
^my.parentD(4,"children",7)=$lb("","children[1,2] cloned")
^my.parentD(4,"children",8)=$lb("","children[1,1] cloned")
^my.parentD(5)=$lb("","parent[3] cloned")
^my.parentD(5,"children",9)=$lb("","children[3,2] cloned")
^my.parentD(5,"children",10)=$lb("","children[3,1] cloned")