cancel
Showing results for 
Search instead for 
Did you mean: 

relation ordered="true" when collectiontype="set"

Former Member
0 Kudos

Hi,

In a relation I want to be able to order my targetElement. When my target has the collectiontype set, the ordered functionality does not work. I don't receive an error.

My code in the items.xml is:

 <relation code="DesignDesignTypeRelation" localized="false" autocreate="true" generate="true">
             <deployment table="des_2_des_typ" typecode="11011"/>
             <sourceElement qualifier="designs" type="Design" cardinality="many"/>
             <targetElement qualifier="designTypes" type="DesignType" cardinality="many" collectiontype="set" ordered="true" />
 </relation>


Without the collectiontype the ordered functionality works

Can somebody explain me what I need to do to order a set?

Accepted Solutions (1)

Accepted Solutions (1)

former_member620692
Active Contributor
0 Kudos

When my target has the collectiontype set, the ordered functionality does not work. I don't receive an error.

Hi - using ordered="true" with collectiontype="set" is not wrong. Please check the following definition in core-items.xml as an example:

 <relation code="ItemSavedValuesRelation" autocreate="true" generate="true" localized="false">
     <sourceElement type="Item" qualifier="modifiedItem" cardinality="one">
         <modifiers read="true" write="false" initial="true" optional="true" search="true"/>
     </sourceElement>
 
     <targetElement type="SavedValues" qualifier="savedValues" cardinality="many" collectiontype="set" ordered="true">
         <modifiers read="true" write="false" optional="true" partof="false"/>
         <model generate="false"/>
     </targetElement>
 </relation>

The definition of ordered is:

 <xs:attribute name="ordered" type="xs:boolean" use="optional">
     <xs:annotation>
         <xs:documentation>If 'true' an additional ordering attribute will be generated for maintaining ordering. Default is 'false'.</xs:documentation>
     </xs:annotation>
 </xs:attribute>

When we use ordered=true, an attribute *POS is added automatically. Please check the definition given below:

 <relation code="house2rooms" localized="false" generate="true" autocreate="true">
    <sourceElement type="House" qualifier="house" cardinality="one">
       <modifiers read="true" write="true" optional="true" search="true"/>
    </sourceElement>
    <targetElement type="Room" qualifier="rooms" cardinality="many" ordered="true" collectiontype="set">
       <modifiers read="true" write="true" optional="true" search="true" partof="true" />
    </targetElement>
 </relation>

Based on the definition given above, we can import the value of housePOS as follows:

 INSERT_UPDATE house;code[unique=true]
 ;house_arvind
 
 INSERT_UPDATE Room;code[unique=true];house(code);housePOS
 ;room1;house_arvind;0
 ;room2;house_arvind;1
 ;room3;house_arvind;2

If we don't specify the value of housePOS, it will be inserted as 0 e.g. as with the following ImpEx:

 INSERT_UPDATE Room;code[unique=true];house(code)
 ;room4;house_arvind
 ;room5;house_arvind

We can execute the following FS query to verify the result:

 SELECT {code},{housePOS} FROM {Room}

Please note that I haven't added housePOS myself; it was automatically added. Given below is my definition of House and Room itemtypes:

 <itemtype generate="true" code="House" autocreate="true">
     <deployment table="houses" typecode="30269" />   
      <attributes>
          <attribute qualifier="code" type="java.lang.String">                     
              <persistence type="property" />
          </attribute>
       </attributes>
 </itemtype>
 <itemtype generate="true" code="Room" autocreate="true">
     <deployment table="rooms" typecode="30270" />
     <attributes>
         <attribute qualifier="code" type="java.lang.String">
             <persistence type="property" />
         </attribute>
     </attributes>
 </itemtype>

Now, it's up to you how you want to use housePOS.

I hope, it is clear.


Best regards.

Answers (1)

Answers (1)

Former Member
0 Kudos

When i look at your example, the order is saved on the target element. I would expect that the sequence on the relation should be used to save this order. In my project the sequence is correct, but when I want to change the order, I can not drag and drop this in my backoffice. If I don't set the collectiontype I can drag and drop, but than I can also add double values. Could this have something to do with the many to many relation?

Best regards

former_member620692
Active Contributor
0 Kudos

Hi - I think you have changed the cardinality of the following element from one to manyin the question or I might have not looked into your question carefully:

 <sourceElement qualifier="designs" type="Design" cardinality="many"/>

Whatever case may be, I wrote the answer considering the cardinality of sourceElement as one.

It is a different case when the cardinality of sourceElement also is many. In this case, the attribute *POS is not generated. In this case, you will notice that irrespective of whether ordered="true" or ordered="false", getDesignTypes() always returns LinkedHashSet<DesignTypes> when collectiontype="set", and List<DesignTypes> when collectiontype="list".

The best thing you can do is going through the generated classes, Design.java and DesignType.java in the gensrc folder of your extension.