1 If you get the following error when retrieving data either from an API route, using Query, or using a module's service:
2
3 ```bash
4 ValidationError: Entity X does not have property Y
5 ```
6
7 ## Why this Error Occurred
8
9 There are different reasons why this error may occur. This troubleshooting guide will help you identify the cause of the error.
10
11 ### Incorrect Property Name
12
13 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.
14
15 For example, a common mistake is retrieving `variant.option` instead of `variant.options`.
16
17 If you're retrieving a property from a Commerce Module, check out the data model references in the [Commerce Modules](../../../commerce-modules/page.mdx) documentation to ensure you're using the correct property name.
18
19 ### Referencing Linked Model with Module's Service
20
21 Another common mistake is passing a linked data model's name to a module's service, which isn't allowed.
22
23 For example, retrieving the customer of an order using the Order Module's service is not allowed:
24
25 ```ts
26 // Don't do this
27 const { data } = await orderService.retrieveOrder("order_123", {
28 relations: ["customer"],
29 })
30 ```
31
32 This isn't allowed because the Order Module's service retrieves data only within the module's scope.
33
34 To retrieve a linked data model like `customer`, use Query instead:
35
36 ```ts
37 // use req.scope instead of container in API routes
38 const query = container.resolve(ContainerRegistrationKeys.QUERY)
39
40 const { data } = await query.graph({
41 entity: "order",
42 fields: ["customer.*"],
43 filters: {
44 id: "order_123",
45 },
46 })
47 ```
48
49 ### Referencing Non-Existent Relation
50
51 To expand a relation of a data model, the data model must have a [relationship property](!docs!/learn/fundamentals/data-models/relationships) in its definition.
52
53 For example, consider you have the following data model:
54
55 ```ts
56 import { model } from "@medusajs/framework/utils"
57
58 const Post = model.define("post", {
59 id: model.id().primaryKey(),
60 title: model.text(),
61 author_id: model.text(),
62 })
63
64 export default Post
65 ```
66
67 Even if you have an `Author` data model, it's not possible to retrieve the post's author using the `author`:
68
69 ```ts
70 // Don't do this
71 const post = await postService.retrievePost("post_123", {
72 relations: ["author"],
73 })
74 ```
75
76 This will throw the `ValidationError` because the `Post` data model doesn't have a relationship property with the `Author` data model.
77
78 Instead, add the author as a relationship property to the `Post` data model:
79
80 ```ts
81 import { model } from "@medusajs/framework/utils"
82 import Author from "./author"
83
84 const Post = model.define("post", {
85 id: model.id().primaryKey(),
86 title: model.text(),
87 author: model.belongsTo(() => Author, {
88 mappedBy: "posts",
89 }),
90 })
91
92 export default Post
93 ```
94
95 Now you can retrieve the post's author using the `author`:
96
97 ```ts
98 // You can do this now
99 const post = await postService.retrievePost("post_123", {
100 relations: ["author"],
101 })
102 ```
103
104 ---
105
106 ## Additional Resources
107
108 - [Data Model Relationships](!docs!/learn/fundamentals/data-models/relationships)
109 - [Module Links](!docs!/learn/fundamentals/module-links)
110 - [Query](!docs!/learn/fundamentals/query)