Hi all,
so I’m once again exploring computations and CDMs. This is mostly a PSA because I found this surprising and somewhat inconsistent but I also have some questions. So I recently stumbled upon the following behavior in CDMs:
When I have a CDM that includes a model with a to-1 relationship (so either the parent in a 1:n parent-child relationship or a sibling in a 1:1 sibling relationship) and this model has a computation with no precondition (or with a precondition that results in the computation being executed even though the document is still empty), then my application will create not only a document of the model that is in the root group of my CDM but also a linked document of the linked model (that is empty with the excception of the computed field).
So as an concrete example: I have a Parent_DM that is linked to a Child_DM via a 1:99 relationship, and I have a Child_CDM that includes both of those models (so I can set the parent of the child via a binding in the Child_FM form model based on Child_CDM). Whenever I add a new Child document with that Child_FM, I always also create an empty Parent document that is linked to my new Child document, unless I link an already existing Parent document.
The same thing happens when I have a Toy_DM that is linked to the Child_DM via a 1:1 relationship and included in the Child_CDM (so every new child document will always already have an empty “ghost” toy document linked to it).
This is not true for the to-n part of a relationship, so in the first example, creating a new Parent document via a Parent_CDM will not result in 99 empty Child documents that are linked to the new Parent document.
I can prevent this by adjusting the preconditions of my computations to only fire when the document is already filled or excluding all computations from this model in the CDM. Both of these are not really great in my specific use case because I have a bunch of computed sums in my models, so I actually like that these get filled with a 0 when the fields involved in that sum are still empty. And because I have a bunch of computations that I would like to get updated when a related document is updated, I don’t love turning off all computations for all to-1-related models in my CDM.
So my questions are:
-
Can anyone point me to a place in the documentation where this is explained? I found some reference to it in the chapter on computed field in CDM-based overviews ( GetA12 ) but this is true for all computed fields in a CDM regardless of whether they are used in an overview or not. It also doesn’t mention that this is only true for to-1 related models.
-
Can I turn the automatic creation of new documents and new links off somehow? Because I actually want these computations to be executed just only for existing documents that have already been linked.
Best,
Lea
Hi @lea-clear-clover,
You’re looking for this part of the documentation.
“In order to determine, whether a link has been established and a child document is present in the respective repetition, a technical field can be used. This field will only be filled when a link is created and a child document is present.
…
However, it can be used to ensure that computed data is not written into fields that are not persisted (no document present).”
Basically, the computations should have a precondition like this:
FieldFilled(t_docRef)
But doesn’t that say the exact opposite of what is happening? The data is persisted because a document for the data to go into is automatically created.
This is also only talking about child documents and I’m talking about parent and sibling documents,
Btw, your link didn’t work for me for some reason but this one does: GetA12
Using FieldFilled(t_docRef) also doesn’t solve this problem. In my example, the computation is part of the DM included in the the CDM. t_docRef is not part of the DM so I can’t reference it in the computation.
Edit: I uploaded my example workspace here: <INTERNAL_LINK>
Regarding
It doesn’t matter how the entities logically fit together in your application, A12 Relationship Links are flat and a link “does not have a direction” (see here).
As a result, any Composed Document Model which contains a to-1 relationship to a Document Model which has Computation Rules which always fire will lead to “ghost documents” being created.
What the documentation means when it talks about “Child documents” relates to the structure of the Composed Document Model. For example, in “Child_CDM” that you show in the screenshot and in the workspace, the structure is as follows:
- Root Document Model - Child_DM
- Child Document Models - Parent_DM (through the Relationship ParentChild_RM) and Toy_DM (through the relationship ChildToy_RM).
So, what are your options if your Composed Document Model references “child” Document Models
- by a to-1 Relationship
- which include Computation Rules that always fire, for example with no precondition
Option 1 - Re-model the Computation Rules
-
Navigate to the Include in the CDM (for example “Parent” or “Toy”)
-
Select “Exclude Computation Rules”
-
Re-model (all of the) Computation Rules taking care to add FieldFilled(t_docRef) to the precondition.
-
This then behaves as expected. No, “ghost documents” are created, the rules fire as expected and the base Document Model is unchanged.
-
This has the added benefit of being able to model a trigger field which hides the Parent and Toy Fields that you modeled on Child_FM Form. This is mentions in the Information part of the previously linked documentation.
Option 2 - Enforce that a Link is made
You could write a Validation Rule that checks that the end-user has created a “child” document.
- Add the t_docRef Field
- Model a Validation Rule,
FieldNotFilled(t_docRef)
Option 3 - Use a Form Model based on the Document Model
-
Add a Form Model based on, for example, Child_DM (not Child_CDM)
-
Configure the Applicaiton Model so that new Child documents may be added using this Form, without the CDM context.
-
The Child Document can later be edited in other CDM contexts.
I’ve added these changes to your workspace <INTERNAL_LINK>
What do you think @lea-clear-clover ?
Thank you for the detailed write-up, Malcolm!
We decided to deal with this in our project by making it mandatory for the user to select an already existing document to link in order to prevent the creation of these ghost entities. I still find the documentation a little unclear as to this behavior but if anyone stumbles across this in the future, they hopefully find this post 
Best,
Lea