fix(db-postgres): select hasMany inside arrays and blocks with versions (#10829)
Fixes https://github.com/payloadcms/payload/issues/10780 Previously, with enabled versions, nested select `hasMany: true` fields weren't working with SQL database adapters. This was due to wrongly passed `parent` to select rows data because we store arrays and blocks in versions a bit differently, using both, `id` and `_uuid` (which contains the normal Object ID) columns. And unlike with non versions `_uuid` column isn't actually applicable here as it's not unique, thus we need to save blocks/arrays first and then map their ObjectIDs to generated by the database IDs and use them for select fields `parent` data
This commit is contained in:
@@ -678,6 +678,30 @@ describe('Fields', () => {
|
||||
|
||||
expect(upd.array[0].group.selectHasMany).toStrictEqual(['six'])
|
||||
})
|
||||
|
||||
it('should work with versions', async () => {
|
||||
const base = await payload.create({
|
||||
collection: 'select-versions-fields',
|
||||
data: { hasMany: ['a', 'b'] },
|
||||
})
|
||||
|
||||
expect(base.hasMany).toStrictEqual(['a', 'b'])
|
||||
|
||||
const array = await payload.create({
|
||||
collection: 'select-versions-fields',
|
||||
data: { array: [{ hasManyArr: ['a', 'b'] }] },
|
||||
draft: true,
|
||||
})
|
||||
|
||||
expect(array.array[0]?.hasManyArr).toStrictEqual(['a', 'b'])
|
||||
|
||||
const block = await payload.create({
|
||||
collection: 'select-versions-fields',
|
||||
data: { blocks: [{ blockType: 'block', hasManyBlocks: ['a', 'b'] }] },
|
||||
})
|
||||
|
||||
expect(block.blocks[0]?.hasManyBlocks).toStrictEqual(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('number', () => {
|
||||
|
||||
Reference in New Issue
Block a user