Trying to query by not existing property Error

If you get the following error in your Medusa application's terminal:

Terminal
Trying to query by not existing property LinkModel.X.

Where X is the name of a data model. For example, LinkModel.cart.

Why this Error Occurred#

This error occurs when you're using Query and you're trying to filter by a linked module, which isn't allowed.

For example, assuming you have a Post data model and you linked it to the Cart data model, this isn't allowed:

Code
1const { data } = await query.graph({2  entity: "post",3  fields: ["*"],4  filter: {5    cart: {6      id: "cart_123",7    },8  },9})

You can't filter your custom post data model by the ID of their linked cart.


How to Fix it#

You need to query the link's table directly and apply the filters on its ID columns. For example:

Code
1import PostCartLink from "../links/post-cart"2
3// ...4
5const { data } = await query.graph({6  entity: PostCartLink.entryPoint,7  fields: ["post.*", "cart.*"],8  filters: {9    cart_id: "cart_123",10  },11})

In the above example, you query the PostCartLink data model directly and apply the filters to the cart_id field, which holds the ID of the cart linked to the post. You'll then only retrieve the posts linked to the cart with the ID cart_123.


Additional Resources#

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break