julioarmandof
julioarmandof

Reputation: 33

Hybris CategoryProductRelation type as ItemModel?

Quick question... so in Hybris, I have a query similar to this:

"SELECT {CPR:pk} FROM {CategoryProductRelation as CPR},  ...."

Basically, I need to extract the Product Code and Category Code from Java which I think are available as source / target respectively but my question is, just like there's ProductModel, CategoryModel, etc. is there anything like that for CategoryProductRelation?, probably something like a generic RelationModel to simply extract source / target and go from there?

Upvotes: 1

Views: 851

Answers (1)

enem.dev
enem.dev

Reputation: 124

You'll need to JOIN in the entities like this

SELECT {CPR:pk}, {c.code} FROM {CategoryProductRelation as CPR 
JOIN Category AS c on {CPR.source} = {c.PK} } WHERE ...

Also, you can do that in the Service Layer by simply calling your query and accessing the properties right from the relation type:

..
CategoryProductRelationModel model = result.get(0)
String categoryCode = ((CategoryModel)model.getSource()).getCode()

Depending on your amount of data, this could be pretty ineffecient.

Upvotes: 1

Related Questions