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

Error: Cannot find module '@payloadcms/plugin-relationship-object-ids' #4

Open
zazz-ops opened this issue Jan 28, 2024 · 7 comments
Open

Comments

@zazz-ops
Copy link

I'm attempting to install this plugin and I'm getting a fireworks of errors.

First, when I follow the instructions in the README that say "just import and install it" I get the following error:
Error: Cannot find module '@payloadcms/plugin-relationship-object-ids'

So I thought maybe I needed to install it from npm, so I run npm install --save @payloadcms/plugin-relationship-object-ids and I get the following error:

image

Does this plugin work with Payload 2.8.1? If so, how do I go about utilizing it without error?

@zazz-ops
Copy link
Author

zazz-ops commented Feb 3, 2024

@jmikrut Any advice on how I should go about getting this plugin to install properly via npm?

@olivier5741
Copy link

Hi there, I'm running through the same issue. I suppose the plugin payloadCMS version needs to be upgraded from 1.9.5 to 2.x.x :). I have no idea about the impact, it looks like a beforeChange hook assigned to every relationship field.

@olivier5741
Copy link

I created a draft pull request for the issue :) : #5

@Rikhart
Copy link

Rikhart commented Apr 12, 2024

Hi @olivier5741 i am facingt the same issue, now i am using payload 2.12.1 also i has been tested your fork but always save as a String the relationship fields.

I am importing and using as the docs says

Captura de pantalla 2024-04-11 a la(s) 11 37 39 p  m

Exist something that i missing in the configuration or something aditiontal in the collection setup to get that my fields save as a Object Id?

Thanks for your help.

@olivier5741
Copy link

Hi @Rikhart, I forgot to commit a peer dependency that I just synced now but I don't know if it has an effect. Last time, I copy pasted the content of /dist into my project to use it and it seemed to work. I now abandonned this plugin, there were too many problems coming up. I just accepted relations (foreign key) to be a string and not an object id. Anyway, in one or two collection I had the ids being a "human comprehensive" string instead of an object id anyway :D

@olivier5741
Copy link

Some extra updates, so I'm using gatsbyjs on the same database, fairly easy to make it work with objectids as string. I'm also using Mongo Charts but there it's a pain to do relationships when foreign keys are string, you need to convert formats ...

@olivier5741
Copy link

I'm still looking for a work around to make payload happy and have the other tools happy as well. One idea is to keep Payload doing its stuff and add an extra field to hold the ObjectId. This only works if you update documents solely through Payload ...

    {
      name: 'place',
      type: 'relationship',
      relationTo: 'places',
      hasMany: false, 
    },
    {
      name: 'placeId',
      type: 'richText',
      hooks: {
        beforeChange: [({ siblingData}) => {
          if(!siblingData.place) return siblingData.place
          return new Types.ObjectId(siblingData.place)
        }]
      },
      admin: {
        hidden: true
      }
    },
`
``

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

No branches or pull requests

3 participants