fix(db-postgres): allow to clear select fields with hasMany: true (#9464)

### What?
Previously, using Postgres, select fields with `hasMany: true` weren't
clearable.
Meaning, you couldn't pass an empty array:
```ts
const updatedDoc = await payload.update({
  id,
  collection: 'select-fields',
  data: {
    selectHasMany: [],
  },
})
```

### Why?
To achieve the same behavior with MongoDB.

### How?
Modifies logic in `packages/drizzle/src/upsertRow/index.ts` to include
empty arrays.
This commit is contained in:
Sasha
2024-11-25 18:15:19 +02:00
committed by GitHub
parent b96475b7b9
commit e5cc9153aa
2 changed files with 30 additions and 8 deletions

View File

@@ -521,6 +521,25 @@ describe('Fields', () => {
expect(updatedDoc.selectHasMany).toEqual(['one', 'two'])
})
it('should clear select hasMany field', async () => {
const { id } = await payload.create({
collection: 'select-fields',
data: {
selectHasMany: ['one', 'two'],
},
})
const updatedDoc = await payload.update({
id,
collection: 'select-fields',
data: {
selectHasMany: [],
},
})
expect(updatedDoc.selectHasMany).toHaveLength(0)
})
it('should query hasMany in', async () => {
const hit = await payload.create({
collection: 'select-fields',