AnsweredAssumed Answered

Bi-Directional Associations

Question asked by stevewickii on Sep 17, 2008
Latest reply on Oct 5, 2017 by clementus
I am using Alfresco 2.9.0B build 683.
I need to create a bidirectional association between a cm:product and a cm:pest.  All my attempts have failed.  Please help.

I followed these directions: http://wiki.alfresco.com/wiki/Data_Dictionary_Guide#Non-Child_Associations

customModel.xml
<?xml version="1.0" encoding="UTF-8"?>

<!– Custom Model –>

<!– Note: This model is pre-configured to load at startup of the Repository.  So, all custom –>
<!–       types and aspects added here will automatically be registered –>

<model name="custom:customModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Custom Model</description>
   <author>Stephen M. Wick</author>
   <version>1.0</version>

   <imports>
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <!– NOTE: The following namespace custom.model should be changed to reflect your own namespace –>
   <namespaces>
      <namespace uri="custom.model" prefix="custom"/>
   </namespaces>

   <types>
      <type name="cm:product">
         <title>Product</title>
         <parent>cm:content</parent>
         <associations>
            <association name="cm:crops">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:crop</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="cm:pests">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:pest</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
      <type name="cm:crop">
         <title>Crop</title>
         <parent>cm:content</parent>
         <associations>
            <association name="cm:products">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:product</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="cm:pests">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:pest</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
      <type name="cm:pest">
         <title>Pest</title>
         <parent>cm:content</parent>
         <associations>
            <association name="cm:products">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:product</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="cm:crops">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:crop</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
   </types>
</model>

I get this error: org.alfresco.service.cmr.dictionary.DictionaryException: Found duplicate association definition cm:pests within class cm:crop and class cm:product

This uni-directional model works great…  I just can't see which cm:product(s) are associated with my cm:crop form the Details screen for the cm:crop.

unidirectional-customModel.xml
<?xml version="1.0" encoding="UTF-8"?>

<!– Custom Model –>

<!– Note: This model is pre-configured to load at startup of the Repository.  So, all custom –>
<!–       types and aspects added here will automatically be registered –>

<model name="custom:customModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Custom Model</description>
   <author>Stephen M. Wick</author>
   <version>1.0</version>

   <imports>
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <!– NOTE: The following namespace custom.model should be changed to reflect your own namespace –>
   <namespaces>
      <namespace uri="custom.model" prefix="custom"/>
   </namespaces>

   <types>
      <type name="cm:product">
         <title>Product</title>
         <parent>cm:content</parent>
         <associations>
            <association name="cm:crops">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:crop</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="cm:pests">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:pest</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
      <type name="cm:crop">
         <title>Crop</title>
         <parent>cm:content</parent>
      </type>
      <type name="cm:pest">
         <title>Pest</title>
         <parent>cm:content</parent>
      </type>
   </types>
</model>

Keywords: bidirectional two-way two way association relationship node

Outcomes