cancel
Showing results for 
Search instead for 
Did you mean: 

Removing association -> Integrity violation

calle
Champ in-the-making
Champ in-the-making
On a type I have the association

<aspect name="tk:relatedDocuments">
                    <title>Related documents</title>
                    <associations>
                                  <association name="tk:relateByAssocation">
                                               <title>Associated documents</title>
                                               <target>
                                                       <class>ver:version</class>
                                                       <mandatory>false</mandatory>
                                                       <many>true</many>
                                               </target>
                                  </association>
                    </associations>
</aspect>

Essentially this is only used for creating references between content.

The association is populated by a search and when a new search is conducted the old associations should be replaced with new ones. And this is resulting in a integrity violation:
The association source multiplicity has been violated:
   Target Node: workspace://lightWeightVersionStore/dba1ad09-a10f-11dd-9061-815ef8c051c2
   Association: Association[ class=ClassDef[name={http://www.jonkoping.se/alfresco/model/tk}relatedDocuments], name={http://www.jonkoping.se/alfresco/model/tk}relateByAssocation, target class={http://www.alfresco.org/model/content/1.0}content, source role=null, target role=null]
   Required source Multiplicity: 1..1
   Actual source Multiplicity: 0

The code to delete the association is as follows:
nodeService.removeAssociation(a.getSourceRef(), a.getTargetRef(), JkpTkModel.ASSOC_RELATE_BY);
where "a" is the association.

The same error occurs if I try to delete the association in the contents property sheet so my guess it is not in the code but in the model…

//Carl
1 REPLY 1

calle
Champ in-the-making
Champ in-the-making
Of course the solution was a simple error in the model. The association source needs to have property mandatory=false (as below)!

    <aspect name="tk:relatedDocuments">
                        <title>Related documents</title>
                        <associations>
                                      <association name="tk:relateByAssocation">
                                                   <title>Associated documents</title>
                                                   <source>
                                                          <mandatory>false</mandatory>
                                                   </source>
                                                   <target>
                                                           <class>ver:version</class>
                                                           <mandatory>false</mandatory>
                                                           <many>true</many>
                                                   </target>
                                      </association>
                        </associations>
    </aspect>