ValidationError: Entity X does not have property Y
If you get the following error when retrieving data either from an API route, using Query, or using a module's service:
Why this Error Occurred#
There are different reasons why this error may occur. This troubleshooting guide will help you identify the cause of the error.
Incorrect Property Name#
The most common reason for this error is that the property name you're using is incorrect. Make sure the property name is spelled correctly and matches the property name in the entity.
For example, a common mistake is retrieving variant.option
instead of variant.options
.
If you're retrieving a property from a Commerce Module, check out the data model references in the Commerce Modules documentation to ensure you're using the correct property name.
Referencing Linked Model with Module's Service#
Another common mistake is passing a linked data model's name to a module's service, which isn't allowed.
For example, retrieving the customer of an order using the Order Module's service is not allowed:
This isn't allowed because the Order Module's service retrieves data only within the module's scope.
To retrieve a linked data model like customer
, use Query instead:
Referencing Non-Existent Relation#
To expand a relation of a data model, the data model must have a relationship property in its definition.
For example, consider you have the following data model:
Even if you have an Author
data model, it's not possible to retrieve the post's author using the author
:
This will throw the ValidationError
because the Post
data model doesn't have a relationship property with the Author
data model.
Instead, add the author as a relationship property to the Post
data model:
Now you can retrieve the post's author using the author
: