#Unable to save/read relationship

3 messages · Page 1 of 1 (latest)

worldly shadow
#

I have following collection that has relation to two different collections. Code below:

import { tenantField } from '../../fields/TenantField'
import { relationToElementsAfterReadHook } from '@/cms/hooks/relationToElementsAfterReadHook'
import { relationToElementsBeforeChangeHook } from '@/cms/hooks/relationToElementsBeforeChangeHook'

export const IncipientMobile: CollectionConfig = {
  slug: 'incipientmobile',
  admin: {
    group: 'Layouts'
  },
  hooks: {
    afterRead: [relationToElementsAfterReadHook]
  },
  fields: [
    tenantField,
    {
      name: 'slug',
      type: 'text',
      required: true,
    },
    {
      name: 'body',
      label: 'bodyComposition',
      type: 'array',
      fields: [
        {
          name: 'id',
          type: 'relationship',
          relationTo: [
            'bannerCarousels',
            'highlightMenus',
          ],
          required: true,
        },
      ],
      required: true,
    },
  ]
}```

rq sent by the browser has when creating collection from UI is:
``` {"slug":"dasda","tenant":"7faddce1-cf9f-4069-aa41-928203a0a27b","body":[{"id":{"relationTo":"highlightMenus","value":"67992eebaa3f188d3f4e8e4b"}}]} ```

but logging data CollectionBeforeChangeHook i get
``` {"slug":"dasda","tenant":"7faddce1-cf9f-4069-aa41-928203a0a27b","body":[{"id":"[object Object]"}]} ```

HTTP response is
> This relationship field has the following invalid relationships: [object Object] 0","path": "body.0.id
> 

is there any way to fix this?
worldly shadow
#

changing field from id -> relId solved this issue. sorry for this 🙂