How to use DeepClone

0
Hi Mendix-Community, I'm trying to copy an object of the entity "Assessment" with all associated questions. In the domain model it looks like this:   My understanding is that the "DeepClone" Java action from the community commons should do that trick but I'm not getting it to work. My microflow looks like this:   and DeepClone is configured like this:     I've also tried the expression in reverse associations and Members to keep empty.   Just to be complete here's also the button that calls the microflow:   Looking forward to your ideas and solutions!   I'm using Mendix Studio Pro 10.14 (not available in the list, yet)
asked
2 answers
0

Vincent,

I wanted to make sure I understood how this works, so I created a test project.  It is similar to the structure you describe.

 

Here is the Domain Model I created:

image.png

I added the autonumber attributes to better understand the behavior of DeepClone.

 

I created a page to see the objects:

image.png

The button highlighted in red points to a DeepClone microflow.

 

Here is what the page looks like after I create one Assessment with 2 questions:

image.png

 

And here is what the microflow looks like:

image.png

 

Initially, I configured DeepClone like this:

image.png

 

The result of this was:

image.png

The Questions were not cloned.

 

So I made this adjustment in DeepClone:

image.png

 

And the result was this:

image.png

Assessment AND Questions were cloned.  I think this is what you were trying to achieve.

 

Note that this is a 'Reverse' association because the Many entity of the 1>>Many association is what you want to clone.  If you used DeepClone to Clone the questions, you could leave all arguments except Source and Target empty and the Question would be cloned as well as the Assessment.

 

Hope that helps,

Mike

 

 

answered
0

From the Javasource:

/**
 * Clones objects, their associations and even referred objects.
 *
 * - Source: the original object to copy
 * - Target: the object to copy it into (should be of the same type, or a specialization)
 * - MembersToSkip: members which should not  be set at all
 * - MembersToKeep: references which should be set, but not cloned. (so source and target will refer to exactly the same object). If an association is not part of this property, it will be cloned.
 * - ReverseAssociations: 1 - 0 assications which refer to target, which will be cloned as well. Only the reference name itself needs to be mentioned.
 * - excludeEntities: entities that will not be cloned. references to these entities will refer to the same object as the source did.
 * - excludeModules: modules that will have none of their enities cloned. Behaves similar to excludeEntities.
 *
 * members format: <membername> or <module.association> or <module.objecttype/membername>, where objecttype is the concrete type of the object being cloned.
 *
 * reverseAssociation:
 * <module.relation>
 *
 * membersToSkip by automatically contains createdDate and changedDate.
 * membersToKeep by automatically contains System.owner and System.changedBy
 *

 * Note that DeepClone does commit all objects, where Clone does not.
 */

 

And from the source code it looks like it is checking for null. So do not enter empty but keep the field empty and do not enter anything.

 

Regards,

Ronald

answered