www/apps/resources/app/lint/rules/link-no-cross-module-relationship/page.mdx
export const metadata = {
title: 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.
error. This rule is enabled in the recommended preset.
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:
import { model } from "@medusajs/framework/utils"
import Product from "@medusajs/medusa/product/models/product"
export const Post = model.define("post", {
product: model.belongsTo(() => Product, {}),
})
Instead, reference a same-module data model and use a module link for cross-module references:
import { model } from "@medusajs/framework/utils"
import Author from "./author"
export const Post = model.define("post", {
author: model.belongsTo(() => Author, {}),
})
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.
This rule isn't auto-fixable.