If we have an enum as one of the attributes of our ItemType, then searching for it using flexible search requires us to do a JOIN.
Since Enum values are stored in the table Enumerationvalue item, we will have to join with that table in our Flexible query.
Let’s assume we have the following enumtype defined in our -items.xml:
<enumtypes>
<enumtype generate="true" code="OrderState" autocreate="true">
<value code="SHIPMENT_PENDING" />
<value code="PO_PENDING" />
<value code="CANCELLATION_PENDING" />
</enumtype>
</enumtypes>
And we are using this enum as one of our attributes of the Order model, like the following:
...
<attribute qualifier="orderState" type="OrderState">
<description>Order State</description>
<modifiers read="true" write="true" optional="true" />
<persistence type="property" />
</attribute>
...
Now, let’s say we want a Flexible query to search for all the orders with PO_PENDING OrderState, then the flexible query would like the following:
SELECT {pk} FROM {Order as o JOIN enumerationvalue as enum on {o.orderState} = {enum.pk}} WHERE {enum.code} = 'PO_PENDING'
View all of my posts on Hybris here.
0 Comments