Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenant Invalid Relationship when installing multi-tenant example #10874

Closed
jotapee opened this issue Jan 29, 2025 · 4 comments
Closed

Tenant Invalid Relationship when installing multi-tenant example #10874

jotapee opened this issue Jan 29, 2025 · 4 comments

Comments

@jotapee
Copy link

jotapee commented Jan 29, 2025

Describe the Bug

Hi,

I'm having issues trying to use the multi-tentant example.

After following indications I get:

`node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/payload/src/fields/config/sanitize.ts:114
throw new InvalidFieldRelationship(field, relationship)
^

InvalidFieldRelationship: Field Tenant has invalid relationship 'undefined'.`

Link to the code that reproduces this issue

Reproduction Steps

Run:

npx create-payload-app --example multi-tenant

Then:

npm run dev or yarn dev

Which area(s) are affected? (Select all that apply)

area: core, area: templates

Environment Info

"dependencies": {
    "@payloadcms/db-mongodb": "latest",
    "@payloadcms/next": "latest",
    "@payloadcms/plugin-multi-tenant": "latest",
    "@payloadcms/richtext-lexical": "latest",
    "@payloadcms/ui": "latest",
    "cross-env": "^7.0.3",
    "dotenv": "^8.2.0",
    "graphql": "^16.9.0",
    "next": "^15.0.0",
    "payload": "latest",
    "qs-esm": "7.0.2",
    "react": "19.0.0",
    "react-dom": "19.0.0",
    "sharp": "0.32.6"
  },
  "devDependencies": {
    "@payloadcms/graphql": "latest",
    "@swc/core": "^1.6.13",
    "@types/react": "19.0.1",
    "@types/react-dom": "19.0.1",
    "eslint": "^8.57.0",
    "eslint-config-next": "^15.0.0",
    "tsx": "^4.16.2",
    "typescript": "5.5.2"
  },

Tried Node: 18.20.2, v18.20.5, v20.16.0 and v22.0.0
@jotapee jotapee added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 29, 2025
Copy link
Contributor

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@beta -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources

@janbiasi
Copy link

@jotapee the issue is that the example is already outdated, and it seems like there's no check nor a guarantee if the example works. To fix your local setup, head to the ./src/collections/User/index.ts file and and the missing tenantsCollectionSlug property like this:

const defaultTenantArrayField = tenantsArrayField({
  tenantsCollectionSlug: "tenants", // this is missing in the example
  arrayFieldAccess: {},
  tenantFieldAccess: {},
  rowFields: [
    {
      name: "roles",
      type: "select",
      defaultValue: ["tenant-viewer"],
      hasMany: true,
      options: ["tenant-admin", "tenant-viewer"],
      required: true,
    },
  ],
});

@jotapee
Copy link
Author

jotapee commented Jan 30, 2025

@janbiasi thank you very much.

I was looking for a configuration problem considering that was the official example. I never imagined it could be broken from the get go.

Thanks for your help.

@jotapee jotapee closed this as completed Jan 30, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jan 30, 2025
Copy link
Contributor

github-actions bot commented Feb 1, 2025

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants