Allow perTenant collections to have relationship fields pointing to isGlobal collections #15131
etaaaaaaa
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description
When using the
@payloadcms/plugin-multi-tenantplugin with a combination ofisGlobaland tenant-scoped (perTenant) collections, the plugin throws an error if aperTenantcollection contains a relationship field that references anisGlobalcollection:Error: The collection homepage is a global collection and cannot be related to a tenant enabled collection.Use Case
We have a multi-tenant website builder where:
isGlobalcollections (one record per tenant): "Homepage", "FAQ", "Services", "Contact", etc. - these are singleton pages that each tenant has exactly one of.perTenantcollection: "Pages" - a flexible collection where tenants can create unlimited custom pages.isGlobalandperTenantcollections need link fields that allow editors to create internal links to ANY page type (polymorphic relationship).The problem: When the "Pages" collection (
perTenant) contains a link field withrelationTo: ["homepage", "faq", "services", "pages"], the plugin throws an error because "homepage", "faq", and "services" areisGlobalcollections. See lines 46-48 and 56-58.Why This Restriction Seems Unnecessary
What's happening:
isGlobal= one document per tenant (e.g., each tenant has exactly one "Homepage")perTenant= many documents per tenant (e.g., each tenant can create many "Pages")What we want:
A "Page" should be able to link to the "Homepage" and visa versa (both belong to the same tenant).
The current code blocks this for no clear reason. Both document types are tenant-scoped, just with different cardinality (one vs many). The relationship is within the same tenant.
Proposed Solution
Simply remove or disable the
throw new Error()statements inaddFilterOptionsToFields.tsthat block this relationship type:This works locally and causes no visible issues right away. Relationship is able to be established successfully.
Questions
Environment
@payloadcms/plugin-multi-tenant: ^3.68.3
payload: ^3.68.3
Beta Was this translation helpful? Give feedback.
All reactions