You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm trying to populate the 'product.facetValues.facet' relation of a ProductVariant. I obtain the ProductVariants from ProductVariantService.findByIds(), so they don't have the product relation yet.
There seem to be two related bugs in EntityHydrator.getMissingRelations:
Line 151 doesn't take the possibility of an empty array into account, setting entity to undefined, which throws an error when trying to hydrate a further nested relation.
After Line 160, entity is not updated, so that the next part of the relation path is checked against the wrong entity.
To Reproduce
Steps to reproduce the behavior:
Create a Product with some facet values, and a ProductVariant without facets
Use this.entityHydrator.hydrate(ctx, variant, { relations: ['product.facetValues.facet'] }):
-> It throws the error "Cannot read property 'facet' of undefined" due to:
The missing product relation is correctly added to missingRelations, however entity is not updated
facetValues is confirmed to exist on the ProductVariant (not ProductVariant.product!), but in this case it's an empty array, so the new value for entity becomes undefined
Use this.entityHydrator.hydrate(ctx, variant, { relations: ['product.facetValues'] }):
It only hydrates the product relation, because facetValues is checked against the ProductVariant, not the Product.
It works when hydrating the nested relations level-by-level:
Describe the bug
I'm trying to populate the 'product.facetValues.facet' relation of a ProductVariant. I obtain the ProductVariants from
ProductVariantService.findByIds()
, so they don't have theproduct
relation yet.There seem to be two related bugs in
EntityHydrator.getMissingRelations
:entity
toundefined
, which throws an error when trying to hydrate a further nested relation.entity
is not updated, so that the nextpart
of the relation path is checked against the wrong entity.To Reproduce
Steps to reproduce the behavior:
this.entityHydrator.hydrate(ctx, variant, { relations: ['product.facetValues.facet'] })
:-> It throws the error "Cannot read property 'facet' of undefined" due to:
product
relation is correctly added tomissingRelations
, howeverentity
is not updatedfacetValues
is confirmed to exist on the ProductVariant (not ProductVariant.product!), but in this case it's an empty array, so the new value forentity
becomesundefined
this.entityHydrator.hydrate(ctx, variant, { relations: ['product.facetValues'] })
:product
relation, becausefacetValues
is checked against the ProductVariant, not the Product.Expected behavior
EntityHydrator should work with nested relations.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: