๐Ÿ“ฆ payloadcms / plugin-relationship-object-ids

A Payload plugin to store all relationship IDs as ObjectIDs

โ˜… 12 stars โ‘‚ 3 forks ๐Ÿ‘ 12 watching โš–๏ธ MIT License
payload-plugin
๐Ÿ“ฅ Clone https://github.com/payloadcms/plugin-relationship-object-ids.git
HTTPS git clone https://github.com/payloadcms/plugin-relationship-object-ids.git
SSH git clone git@github.com:payloadcms/plugin-relationship-object-ids.git
CLI gh repo clone payloadcms/plugin-relationship-object-ids
James Mikrut James Mikrut Merge pull request #6 from payloadcms/feat/keepAfterRead c7d9720 1 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .vscode
๐Ÿ“ dev
๐Ÿ“ eslint-config
๐Ÿ“ src
๐Ÿ“„ .editorconfig
๐Ÿ“„ .eslintrc.js
๐Ÿ“„ .gitignore
๐Ÿ“„ .prettierignore
๐Ÿ“„ .prettierrc.js
๐Ÿ“„ LICENSE.md
๐Ÿ“„ package.json
๐Ÿ“„ pnpm-lock.yaml
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

Payload Relationship ObjectID Plugin

This plugin automatically enables all Payload relationship and upload field types to be stored as ObjectIDs in MongoDB.

Minimum required version of Payload: 1.9.5

What it does

It injects a beforeChange field hook into each relationship and upload field, which converts string-based IDs to ObjectIDs immediately prior to storage.

Usage

Simply import and install the plugin to make it work:

import { relationshipsAsObjectID } from '@payloadcms/plugin-relationship-object-ids'
import { buildConfig } from 'payload/config'

export default buildConfig({
  // your config here
  plugins: [
    // Call the plugin within your `plugins` array
    relationshipsAsObjectID()
  ]
})

Migration

Note - this plugin will only store newly created or resaved documents' relations as ObjectIDs. It will not modify any of your existing data. If you'd like to convert existing data into an ObjectID format, you should write a migration script to loop over all documents in your database and then simply resave each one.

Support

If you need help with this plugin, join our Discord and we'd be happy to give you a hand.