cancel
Showing results for 
Search instead for 
Did you mean: 

child association trouble

mzaranto
Champ in-the-making
Champ in-the-making
Hi to everyone!
I was trying to model a parent-child association, in order to get automatic cascade when deleting or moving the parent. This is the code of the custom model:


                                        <child-association name="custom:associationName">
                                                <title>Allegati</title>
                                                <source>
                                                        <mandatory>false</mandatory>
                                                        <many>false</many>
                                                </source>
                                                <target>
                                                        <class>custom:otherCustomType</class>
                                                        <mandatory>false</mandatory>
                                                        <many>true</many>
                                                </target>
                                                <duplicate>false</duplicate>
                                                <propagateTimestamps>true</propagateTimestamps>
                                        </child-association>

Sadly, cascading delete isn't working Smiley Sad Am I missing something? Is it because I am omitting the "role" tag on source and target (by the way, what's the purpose of naming roles)?

Looking forward to your answers…

Marco
9 REPLIES 9

derek
Star Contributor
Star Contributor
The roles are not important.

Cascade-delete is a function of where a node was created rather than the association itself.  If you use your association to create a node, then deleting the node's parent will result in a cascade.  If you use your association to link to a secondary parent, then deleting the secondary parent will only remove the association but will not cascade.  You will need to write code to listen to the various policies coming from the NodeService, and react accordingly; I'm thinking 'beforeDeleteChildAssociation', in particular.

junieboy
Champ in-the-making
Champ in-the-making
Hi Derek,

Just wanted to make further clarification. Please further elaborate the solution as there seems to be no documentation for this scenario. To implement child association (not peer association) in Java to achieve the cascaded delete functionality, can this be done using Java web services API? If yes, is there any available reference for this?

Also, I believe in your explanation above, you were referring to creating behavior right?

Thanks so much for the information.

derek
Star Contributor
Star Contributor
Hi,
Delete only cascades along the single child association used to create the child node, known as the primary child association.  If you create child associations between pre-existing nodes, then delete will not cascade along them.
Regards

viralshah
Champ in-the-making
Champ in-the-making
How does one create a primary child asociation using the Alfresco Explorer? Right now the explorer gives option to select only content "existing" on any space of Alfresco for child /peer associations. Because of which it looks like the child content does not  get deleted even when the parent is getting deleted.

derek
Star Contributor
Star Contributor
@viralshah

You're correct in that the association created by Explorer will always be secondary i.e. the content selected will not be bound in life to the new parent because it can be shared in this way between several parent nodes.  You would have to write your own client extensions if you want to create sub-content (content tied to the parent's lifecycle) through explorer.

Regards

viralshah
Champ in-the-making
Champ in-the-making
Thanks Derek for the confirmation.  Is this not a limitation on the Explorer side?
What are the out-of box options available to create such sub-content ? Will we have to create content using the Web services ?

derek
Star Contributor
Star Contributor
Hi,
When does a potential feature become a limitation?  It's not a limitation yet because we haven't been asked for it by enough people.
You can add behaviour to your association to automatically move the selected content under the new parent and thereby bind it's life to that of the new parent; you would still have to create the content first before selecting it.  If you want to create it at the time, you'll have to enhance the UI.
You can do anything you want through the APIs.
Regards

viralshah
Champ in-the-making
Champ in-the-making
Hi,
How to create primary child content using the webservices ? It seems that even after creating the child content via webservice ( CMLCreate) and relating it to the parent content is creating a secondary child ( the one which will not get cascade delete). 
We tried creatign parentReference with the parent doc ID but it is not working.
Any exmaple code would be useful

cristian
Champ in-the-making
Champ in-the-making
I've read how to implement primary associations between nodes in the Alfresco reference:

java.lang.Object
  extended by org.alfresco.service.cmr.repository.ChildAssociationRef

ChildAssociationRef

public ChildAssociationRef(QName assocTypeQName,
                           NodeRef parentRef,
                           QName childQName,
                           NodeRef childRef,
                           boolean isPrimary,
                           int nthSibling)

    Construct a representation of a parent — name —-> child relationship.

    Parameters:
        assocTypeQName - the type of the association
        parentRef - the parent reference - may be null
        childQName - the qualified name of the association - may be null
        childRef - the child node reference. This must not be null.
        isPrimary - true if this represents the primary parent-child relationship
        nthSibling - the nth association with the same properties. Usually -1 to be ignored