cancel
Showing results for 
Search instead for 
Did you mean: 

unique = true in one to many Relation in items.xml in Hybris

Former Member
0 Kudos
1,945

We have a one to many relation from A2B in our items.xml, question is why is there unique = true used on the source element where cardinality is already one. What is the use of this unique = true and why it should or should not be used? we need to know the significance of it.

Former Member
0 Kudos

Below is the format of relation:

Please help

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member620692
Active Contributor

Hi - having a unique modifier for the qualifier with cardinality="one" creates a unique constraint which does not allow creating a duplicate combination of the records e.g. as per the relation definition given below, you can not insert two records with United Kingdom as Country and London as Region combination.

 <relation code="Country2RegionRelation" generate="true" localized="false" autocreate="true">
     <sourceElement type="Country" qualifier="country" cardinality="one">
         <modifiers read="true" write="true" search="true" optional="false" unique="true"/>
     </sourceElement>
     <targetElement type="Region" qualifier="regions" cardinality="many">
         <modifiers read="true" write="true" search="true" partof="true"/>
     </targetElement>
 </relation>

You can validate this using the following ImpEx which will succeed:

 INSERT_UPDATE Country;isocode[unique=true]
 ;US
 
 INSERT Region;country(isocode);isocode[unique=true]
 ;US;US-AL
 ;US;US-AK

Now, if you try to import the following ImpEx, it will fail:

 INSERT Region;country(isocode);isocode[unique=true]
 ;US;US-AL
former_member620692
Active Contributor
0 Kudos

Hi - did it help?

0 Kudos

hi , if we use insert_update rather than insert , will the unique=true identifier be needed?

former_member620692
Active Contributor
0 Kudos

Hi - if you replace INSERT with INSERT_UPDATE (as given below), it will pass because it will update the existing record instead of trying to create a new duplicate record.

 INSERT-UPDATE Region;country(isocode);isocode[unique=true]
 ;US;US-AL
0 Kudos

so if we are very much sure that the database will be updated using insert_update only, then unique=true can be skipped?