link-no-cross-module-relationship - ESLint plugin rules

This rule requires that data model relationships (hasOne, belongsTo, hasMany, manyToMany) reference a data model defined in the same module.

Severity#

error. This rule is enabled in the recommended preset.

What it Targets#

This rule targets data model files in your project's src/modules directory. It reports a relationship method that references a data model imported from another module.

The following code is reported by the rule:

src/modules/blog/models/post.ts
1import { model } from "@medusajs/framework/utils"2import Product from "@medusajs/medusa/product/models/product"3
4export const Post = model.define("post", {5  product: model.belongsTo(() => Product, {}),6})

Instead, reference a same-module data model and use a module link for cross-module references:

src/modules/blog/models/post.ts
1import { model } from "@medusajs/framework/utils"2import Author from "./author"3
4export const Post = model.define("post", {5  author: model.belongsTo(() => Author, {}),6})

Why it's Important#

Modules are isolated and can't have direct database relationships across module boundaries. Cross-module references are defined with module links instead, which keeps modules decoupled.

Learn more in the Module Links documentation.

Fixable#

This rule isn't auto-fixable.

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