Skip to content

Admin: in Relationship field to multiple collections, when the value is null, options are not populated #459

@oranoran

Description

@oranoran

Bug Report

Relationship field component fails to be populated with options, when it is a relation to multiple collections, and the field doesn't have a value.

Expected Behavior

Should see all available values from the various collections as options in the relationship select.

Current Behavior

Seeing only "None", and the following error in the console:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'relationTo')
    at createRelationMap (createRelationMap.js:23:1)
    at index.js:49:46
    at index.js:158:1
    at invokePassiveEffectCreate (react-dom.development.js:23487:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at HTMLUnknownElement.dispatchEvent (<anonymous>)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)

Possible Solution

I think in admin/components/forms/field-types/Relationship/createRelationMap.ts line 38, it should be else if (hasMultipleRelations && value) rather than just else if (hasMultipleRelations).

Steps to Reproduce

  1. Define a field like so: {name: 'test', type: 'relationship', relationTo: ['some-other-collection']}
  2. Ensure some-other-collection has values
  3. In the admin form, add a new item (at this point the error will show in the console)
  4. Click the relation field to find values to fill in (at this point you will see just None instead of real options)

Detailed Description

Payload version 0.14.25-beta.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions