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

chore(examples): multi-tenant compatible with postgres ID check #9568

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Nov 27, 2024

Fixes #9565 multi-tenant compatibility with Postgres (and custom IDs)

Adds a useful extractID utility:

import { Config } from '@/payload-types'
import type { CollectionSlug } from 'payload'

export const extractID = <T extends Config['collections'][CollectionSlug]>(
  objectOrID: T | T['id'],
): T['id'] => {
  if (objectOrID && typeof objectOrID === 'object') return objectOrID.id

  return objectOrID
}

@jacobsfletch jacobsfletch merged commit 4a854f8 into main Nov 27, 2024
18 checks passed
@jacobsfletch jacobsfletch deleted the templates/tenant-fix-postgres branch November 27, 2024 16:27
Copy link
Contributor

🚀 This is included in version v3.2.2

kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
Fixes #9565 multi-tenant
compatibility with Postgres (and custom IDs)

Adds a useful `extractID` utility:
```ts
import { Config } from '@/payload-types'
import type { CollectionSlug } from 'payload'

export const extractID = <T extends Config['collections'][CollectionSlug]>(
  objectOrID: T | T['id'],
): T['id'] => {
  if (objectOrID && typeof objectOrID === 'object') return objectOrID.id

  return objectOrID
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Database migration from Mongo to Postgres throwing type error in existing files.
2 participants