cancel
Showing results for 
Search instead for 
Did you mean: 

Bi-Directional Associations

stevewickii
Champ in-the-making
Champ in-the-making
I am using Alfresco 2.9.0B build 683.
I need to create a bidirectional association between a cmSmiley Tongueroduct and a cmSmiley Tongueest.  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 cmSmiley Tongueests within class cm:crop and class cmSmiley Tongueroduct

This uni-directional model works great…  I just can't see which cmSmiley Tongueroduct(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
12 REPLIES 12

omer_i
Champ in-the-making
Champ in-the-making
Hi, I followed the way mentioned in the bottom to achieve bidirectional associations.

Although Associations are working fine but it creates a problem… I m not able to version the document. i.e. I cant apply versionable aspect on the document which is overridden with this new association…  It throws this error

"Failed to apply the 'versionable' aspect to the document due to system error: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction ed4e396b-effb-4954-a51c-23b51cd50b71"

Any ideas how to resolve this….

Thanks,
Omer

checco
Champ in-the-making
Champ in-the-making
Hi to all, i'am new to Alfresco.

The bug https://issues.alfresco.com/jira/browse/ALFCOM-588 is still open! and it seems there isn't any activity related to.

Anyone have some news? Actually i don't need this feature but probably in next future i'll need.

Cheers  Smiley Very Happy
Francesco.

clementus
Champ in-the-making
Champ in-the-making

Hi everyone,

I created a control form to handle bidirectional association.

Just email me to get my code.