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. The error may also show your data model's name instead of LinkModel, such as Post.cart.

Why this Error Occurred#

This error occurs when you're using Query to filter by a linked data model's property, and Query can't apply the filter. This happens in the following cases:

  1. You're using a Medusa version before v2.18.0, which doesn't support filtering by linked data models.
  2. You passed the linked data model's filter inside a top-level $and, $or, or $not operator. Query passes these operators as-is to your data model's module, which doesn't recognize the linked data model's property.

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

Code
const { data } = await query.graph({
  entity: "post",
  fields: ["*"],
  filters: {
    $or: [
      {
        cart: {
          id: "cart_123",
        },
      },
      {
        title: "My Post",
      },
    ],
  },
})

How to Fix it#

If you're using Medusa v2.18.0 or later, pass the linked data model's filter as a top-level key in filters:

Code
const { data } = await query.graph({
  entity: "post",
  fields: ["*"],
  filters: {
    cart: {
      id: "cart_123",
    },
  },
})

If you need to combine it with other conditions in an $or operator, run a separate query for each condition and merge the results.

If you're using a Medusa version before v2.18.0, query the link's table directly and apply the filters on its ID columns. For example:

Code
import PostCartLink from "../links/post-cart"

// ...

const { data } = await query.graph({
  entity: PostCartLink.entryPoint,
  fields: ["post.*", "cart.*"],
  filters: {
    cart_id: "cart_123",
  },
})

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 Docs 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
⇧↵