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

feat: support relationship writes using objects instead of IDs #9253

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Nov 16, 2024

What?

Previously, this code led to a validation error because movie is an object and you needed to use movie.id instead.

const movie = await payload.create({ collection: 'movies', data: {} })
const result = await payload.create({
  collection: 'object-writes',
  data: {
    many: [movie],
    manyPoly: [{ relationTo: 'movies', value: movie }],
    one: movie,
    onePoly: {
      relationTo: 'movies',
      value: movie,
    },
  },
})

While it's simple to modify this example, it's more painful when you have a data with depth > 0 and then you want to update that document.

Why?

Better DX as less checks needed, and TypeScript says that we can pass an object.

How?

Sanitizes the field value in the root beforeValidate hook

@r1tsuu r1tsuu merged commit d21fca9 into beta Nov 17, 2024
61 checks passed
@r1tsuu r1tsuu deleted the feat/support-relationship-fields-writes-using-objects branch November 17, 2024 09:25
Copy link

🚀 This is included in version v3.0.0-beta.134

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

Successfully merging this pull request may close these issues.

2 participants