How to configure the relationship of 2 custom modules? #10854
-
Suppose I have 2 custom modules -
{
id: model.id().primaryKey(),
name: model.text(),
page_key: model.enum([...PAGE_KEYS]),
is_active: model.boolean().default(false),
home_page_configuration: model.hasOne(() => HomePageConfiguration).nullable(),
product_banners: model.manyToMany(() => ProductBanner, {
mappedBy: "site_contents",
joinColumn: "site_content_id",
inverseJoinColumn: "product_banner_id",
}),
}
{
id: model.id().primaryKey(),
title: model.text().nullable(),
subtitle: model.text().nullable(),
description: model.text().nullable(),
image_url: model.text(),
categories: model.manyToMany(() => ProductBannerCategory, {
mappedBy: "product_banners",
}),
site_contents: model.manyToMany(() => ProductBanner, {
mappedBy: "product_banners"
}),
} But with this approach, I get an error when calling
After some time, I came to the conclusion that I should try using a link directory. I deleted the fields with the link records of these entities ( export default defineLink(
{
linkable: SiteContentModule.linkable.siteContent,
isList: true,
},
{
linkable: ProductBannerModule.linkable.productBanner,
isList: true,
}
); With this approach the migrations were successfully created, but I am not sure if this approach is correct as it is not described in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@qFlensT, this is the correct approach for associating models across modules. Modules Links are documented here. We would be curious to know what you felt missing in the documentation about this topic. |
Beta Was this translation helpful? Give feedback.
@qFlensT, this is the correct approach for associating models across modules. Modules Links are documented here. We would be curious to know what you felt missing in the documentation about this topic.