Skip to content

Commit 727d74e

Browse files
authored
fix(db-postgres): handle blockType filters for versions (#16071)
Fixes draft `blocks.blockType` filters for postgres adapter. See issue for details. Fixes #16070
1 parent 8045887 commit 727d74e

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

packages/drizzle/src/queries/getTableColumnFromPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const getTableColumnFromPath = ({
221221
constraints.push({
222222
columnName: '_path',
223223
table: newAliasTable,
224-
value: pathSegments[0],
224+
value: `${constraintPath}${pathSegments[0]}`,
225225
})
226226
})
227227
return {

test/versions/int.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,51 @@ describe('Versions', () => {
18271827
expect(draftFindResults.docs[0].title).toStrictEqual(updatedTitle2)
18281828
})
18291829

1830+
it('should be able to query blockType fields with contains and draft=true', async () => {
1831+
const matchingDraft = await createDraftDocument({
1832+
blocksField: [
1833+
{
1834+
blockType: 'block',
1835+
localized: null,
1836+
text: 'Block',
1837+
},
1838+
],
1839+
collection: draftCollectionSlug,
1840+
payload,
1841+
title: 'draft block type query',
1842+
})
1843+
1844+
await createDraftDocument({
1845+
blocksField: [],
1846+
collection: draftCollectionSlug,
1847+
payload,
1848+
title: 'draft block type query 2',
1849+
})
1850+
1851+
const query = {
1852+
'blocksField.blockType': {
1853+
contains: 'block',
1854+
},
1855+
}
1856+
1857+
const publishedFindResults = await payload.find({
1858+
collection: draftCollectionSlug,
1859+
where: query,
1860+
})
1861+
1862+
expect(publishedFindResults.docs).toHaveLength(1)
1863+
expect(publishedFindResults.docs.find(({ id }) => id === matchingDraft.id)).toBeDefined()
1864+
1865+
const draftFindResults = await payload.find({
1866+
collection: draftCollectionSlug,
1867+
draft: true,
1868+
where: query,
1869+
})
1870+
1871+
expect(draftFindResults.docs).toHaveLength(1)
1872+
expect(draftFindResults.docs.find(({ id }) => id === matchingDraft.id)).toBeDefined()
1873+
})
1874+
18301875
it("should not be able to query old drafts that don't match with draft=true", async () => {
18311876
const draftFindResults = await payload.find({
18321877
collection: draftCollectionSlug,

0 commit comments

Comments
 (0)