5

In my hybris application, I wanted to override my CustomerReview item type so that its attributes product and user are not unique anymore.

The uniqueness of these attributes are declared in the relationships between CustomerReview and Product/User. I tried adding the relationship declaration again to my extname-items.xml file and set the appropriate unique="false" attributes, as follows:

<relation generate="false" localized="false" code="ReviewToUserRel" autocreate="false">
    <sourceElement type="User" qualifier="user" cardinality="one">
        <modifiers write="false" initial="true" optional="false" unique="false" />
    </sourceElement>
    <targetElement type="CustomerReview" qualifier="customerReviews" cardinality="many">
        <modifiers write="false" initial="true" />
    </targetElement>
</relation>

This doesn't do the trick though. After I rebuild the application and Update the Running System, the user and product attributes of a CustomerReview are still unique attributes.

So what's the best solution for this problem?

Henrique Ordine
  • 3,337
  • 4
  • 44
  • 70

2 Answers2

4

It's true that rewriting the relation will not override it.

Another way to solve it would be to add an attribute to the type and set that as unique. For instance emailAddress:

<itemtype code="CustomerReview" autocreate="false" generate="false">
    <attributes>
                <attribute type="java.lang.String" qualifier="email">
                    <persistence type="property" />
                    <modifiers read="true" write="true" unique="true"/>
                </attribute>
     </attributes>
</itemtype>

Then you could have multiple reviews from the same user for the same product, as long as the emailAddress differs.

Pearl Jade
  • 716
  • 1
  • 8
  • 22
1

Updating the relation will not overwrite the existing relation. Better create new item definition for CustomerReview and then relate this with product.

Immy
  • 57
  • 2
  • 10