Initially I thought that we will have to add special checks to allow relationships referencing itself. However, it turned out that not to be the case. Instead, it had more to do with how self relationships are defined in Mikro ORM. In case of `belongsTo` relationship we have to define the other side as well either as a `hasMany` or `hasOne`. For example: **❌ The following code will fail, because no children are defined for the parent** ```ts const user = model.define("user", { id: model.number(), username: model.text(), parent: model.belongsTo(() => user) }) ``` **✅ Addition of children relationship will make things work** ```ts const user = model.define("user", { id: model.number(), username: model.text(), parent: model.belongsTo(() => user, { mappedBy: "children" }), children: model.hasMany(() => user, { mappedBy: "parent" }), }) ``` We can see the similar setup here with our `ProductCategory` MikroORM entity. https://github.com/medusajs/medusa/blob/develop/packages/modules/product/src/models/product-category.ts#L87-L94 @adrien2p Correct me if I am wrong. But I have added the tests for now so that we know the behavior of self relationships
Medusa
Documentation | Website
Building blocks for digital commerce
Getting Started
Visit the Documentation to set up a Medusa application.
What is Medusa
Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.
Learn more about Medusa’s architecture and commerce modules in the Docs.
Roadmap, Upgrades & Integrations
You can view the planned, started and completed features in the Roadmap discussion.
Follow the Release Notes to keep your Medusa project up-to-date.
Check out all available Medusa integrations.
Community & Contributions
The community and core team are available in GitHub Discussions, where you can ask for support, discuss roadmap, and share ideas.
Our Contribution Guide describes how to contribute to the codebase and Docs.
Join our Discord server to meet other community members.
Other channels
License
Licensed under the MIT License.