When clearing a relationship field with required: false I get the error
"TypeError: Cannot use 'in' operator to search for 'relationTo' in null"
Is this a bug?
Hi
@456226577798135808, I'm not able to replicate this error - is this happening across all relationship fields or just one? If you could share your code for the relationship field causing the error that would be helpful
1. In The payload demo, select a post.
2. Then select Internal link and fill out the Document to link to,
3. Save the Document.
4. Clear the "Document to link to"
5. Select the option Custom URL
6. Save the Document
Throws "TypeError: Cannot use 'in' operator to search for 'relationTo' in null"
import { CollectionConfig } from "payload/types";
export const Pages: CollectionConfig = {
slug: "pages",
labels: {
singular: "Page",
plural: "Pages",
},
admin: {
useAsTitle: "title",
},
fields: [
{
name: "title",
label: "Title",
localized: true,
type: "text",
required: true,
},
{
name: "related",
label: "Related",
type: "relationship",
relationTo: ["posts" /
"articles"/],
hasMany: false,
required: false,
admin: {
readOnly: false,
},
},
],
};
I guess it's when using an array with relationTo for many relationships
This error is occurring when
hasMany: falseand
relationTois an array - I'll relay this back to the team! For now, could you set
hasManyto
trueand let me know if that works for you?
it works if hasMany: true 🙂
Great - use that for now and we will get the issue fixed soon. Thanks for catching this! 🙌
When localized is true on relationships, it also fails if hasMany is false.
Hey just an update, a fix will be merged and released later on today
Works like a charm 🍻
Star
Discord
online
Get dedicated engineering support directly from the Payload team.