Farhan
Farhan

Reputation: 431

Hybris - ItemType of Relation concept

Lately I have come across instances where people have itemtypes of a relation. Could someone please explain me the concept of this structure?

Also I have generated a relation, but am unable to find getters/setters for this. I believe, this is because no classes are generated for a relation.

For a specific project requirement I had to add a collection of relations to another Model, but could not find the setters and getters generated even for the collection, I think because the elementtype is a relation. I also checked the extensionmanager, but no getters and setters were generated there either.

Could someone please let me know if with such a structure I could getters and setters for collection of relations?

Thanks, Farhan

Upvotes: 2

Views: 1194

Answers (1)

alain.janinm
alain.janinm

Reputation: 20065

First you should use Relation instead of Collection whenever it's possible. In hybris Collection stores the values as CSV in one field, hence it's limited by the max size of a field and it may be truncated.

Then for Relation, you won't have a Java model generated, but only a specific DB table. The getter and setter will actually be generated in the target and source model depending on your cardinality.

If we take an example - EmailMessage2ToAddressesRel

    <relation code="EmailMessage2ToAddressesRel" .... >
        .
        .
        .
        <sourceElement type="EmailMessage" qualifier="toMessages"
            cardinality="many" collectiontype="list" />
        <targetElement type="EmailAddress" qualifier="toAddresses"
            cardinality="many" collectiontype="list" />
    </relation>

It map many toMessages as source to many toAddresses as target.

If you look at EmailMessageModel and EmailAddressModel you will find respectively the getter and setter for toAddresses and toMessages.

Upvotes: 4

Related Questions