From 2ee3e30b5037b8870a742c307d2ad88c6d11172d Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:33:12 +0200 Subject: [PATCH] fix(db-postgres): `select` query on upload fields with `hasMany: true` (#10029) Previously, if you selected only upload `hasMany: true` field, you would receive an empty arrays always, because the `_rels` table wasn't joined in this case. Fixes the condition to count `field.type === 'upload'` . --- packages/drizzle/src/find/traverseFields.ts | 2 +- test/select/collections/Posts/index.ts | 28 +++++ test/select/config.ts | 11 ++ test/select/image.jpg | Bin 0 -> 86124 bytes test/select/int.spec.ts | 123 +++++++++++++++++++- test/select/payload-types.ts | 82 +++++++++++++ 6 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 test/select/image.jpg diff --git a/packages/drizzle/src/find/traverseFields.ts b/packages/drizzle/src/find/traverseFields.ts index b1093073825..712d39da0f7 100644 --- a/packages/drizzle/src/find/traverseFields.ts +++ b/packages/drizzle/src/find/traverseFields.ts @@ -526,7 +526,7 @@ export const traverseFields = ({ if ( !withTabledFields.rels && - field.type === 'relationship' && + (field.type === 'relationship' || field.type === 'upload') && (field.hasMany || Array.isArray(field.relationTo)) ) { withTabledFields.rels = true diff --git a/test/select/collections/Posts/index.ts b/test/select/collections/Posts/index.ts index 3c36d9c2fd0..9aeb0cb6ebd 100644 --- a/test/select/collections/Posts/index.ts +++ b/test/select/collections/Posts/index.ts @@ -116,5 +116,33 @@ export const PostsCollection: CollectionConfig = { }, ], }, + { + type: 'relationship', + name: 'hasOne', + relationTo: 'rels', + }, + { + type: 'relationship', + name: 'hasMany', + hasMany: true, + relationTo: 'rels', + }, + { + type: 'upload', + name: 'hasManyUpload', + hasMany: true, + relationTo: 'upload', + }, + { + type: 'relationship', + name: 'hasOnePoly', + relationTo: ['rels'], + }, + { + type: 'relationship', + name: 'hasManyPoly', + hasMany: true, + relationTo: ['rels'], + }, ], } diff --git a/test/select/config.ts b/test/select/config.ts index 7f0cb3a728b..19a6a38f42b 100644 --- a/test/select/config.ts +++ b/test/select/config.ts @@ -23,6 +23,17 @@ export default buildConfigWithDefaults({ DeepPostsCollection, Pages, Points, + { + slug: 'upload', + fields: [], + upload: { + staticDir: path.resolve(dirname, 'media'), + }, + }, + { + slug: 'rels', + fields: [], + }, ], globals: [ { diff --git a/test/select/image.jpg b/test/select/image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4d2dfc3457f77d859683d71997d0af53c0585dae GIT binary patch literal 86124 zcmeEP2_RJa_rDq%5tBXZD6&=}Qo>L#l%yg{%G6UKNs1z4Mu_Z5rBW!B5RxrfCdN{! zBwO}<-)5|r+5VUI^4`;Xz4!aS7cbtOJ9n1*J?Hy5pL5RloG<+?y$M*fMQgJbz`(!& z?1TOT=*@uDCMWAd0HCJ_$N&Jq3@|bX08G#k1N5uTAo%fEi$My2O`o3!Jt+@Be*q5Y zcN_FO^|KH9oqEmm|BvmrKI*XY=s^cj#g(g9$}2#hR10hbVDsip{eylOp?^%wOiYZ7 zOe}EteCCBL3m3Aou(GnTb1q_I=U``LUBtVHgNvJohi4&zZ!s_TVoq)z?x{CnfI+We zWLm()w1At9m5uwmf9OvD4(9n9^EF@$OMrPC3@{D`dOm=JzC9B(E>lDE{)b^6^d0BJ znHR9ILKmbi0_HKmVDlJZQ{Ni8+7)^pVB}!pTq3VIpKHf{_)>drg)_l7nZ-6F27GA!^`~u4)B&DQf6qVK}uU)6I@s~|n+B%!J7#Qv{GBz>YZE@h>AxkUk z!zUaZPo8peKJDRo*30{xkMD($ih&;I$n)#*QWjou#pY$C zsau=Av)SF4`=7eAk2m(|zG{GlFa}6?Fb)6(Pz`Rmu}A^`?4Lv=7)Cay@PlfdlD;&t zE*00hb&VEGB{d0E!v2fA&*K^u8HVurNN@!*&kiw>Mv`bsz-5#@zJaUBz(cH%E#Jr#8$Vk7PVPC>r7rs&2LZ(rq`pqs-L zL7GYTY1{jYCsCKtbU-9=WfjgwE&wZDr-bxVUmd=tm$Nrrnx781$)2T3!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SuD$KC zj$IC&Xl0xkl#+25RH3CD&!h z68iX@k5X~Nj-u*yB+H!=H-?t18BjFyO(BwHh1QyyvrV*F?FYj8K~+l z6R@H!;ejZo8AugpL`N*TTHOBTmxoN#*TE7`BUW~1Y*@FJd(EYTbeseUPTM1}lMxiI ze$U>o2OYq8_q1i-Zrg~C>6<$Z5Z*jRek@)=P?>#7@fc3&Dz;wFL;tcxh0oN^T*j&= zL%kB&lKcdott}0w z$?VYRfqKOi)FEOil=&PB@$+raP_LwrHda!2Gp{=z5dw*(`&!e50I1R~>Bdp3?+^mo zPMaT$3pcC{`Vdkz8f3mk`=VYzmCdo6g+M6O{ZZyHRQd0OD*v@8PAydVhmXVZf%O9( zA21(aKEn3lulCVcmN&kg4F+dCWCRB#w-xsoX?sGI5|==ZZ5Yw(?U%(E<>Qscf>Vpwl3uFAEv{ { collection: 'posts', id: postId, select: {}, + depth: 0, }) expect(res).toStrictEqual({ @@ -78,6 +79,7 @@ describe('Select', () => { select: { number: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -93,6 +95,7 @@ describe('Select', () => { select: { select: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -108,6 +111,7 @@ describe('Select', () => { select: { selectMany: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -124,6 +128,7 @@ describe('Select', () => { number: true, text: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -133,6 +138,50 @@ describe('Select', () => { }) }) + it('should select relationships', async () => { + const res_1 = await payload.findByID({ + collection: 'posts', + id: postId, + select: { + hasManyUpload: true, + }, + depth: 0, + }) + + expect(res_1).toStrictEqual({ + id: postId, + hasManyUpload: post.hasManyUpload, + }) + + const res_2 = await payload.findByID({ + collection: 'posts', + id: postId, + select: { + hasOne: true, + }, + depth: 0, + }) + + expect(res_2).toStrictEqual({ + id: postId, + hasOne: post.hasOne, + }) + + const res_3 = await payload.findByID({ + collection: 'posts', + id: postId, + select: { + hasManyPoly: true, + }, + depth: 0, + }) + + expect(res_3).toStrictEqual({ + id: postId, + hasManyPoly: post.hasManyPoly, + }) + }) + it('should select all the fields inside of group', async () => { const res = await payload.findByID({ collection: 'posts', @@ -140,6 +189,7 @@ describe('Select', () => { select: { group: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -157,6 +207,7 @@ describe('Select', () => { text: true, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -174,6 +225,7 @@ describe('Select', () => { select: { tab: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -191,6 +243,7 @@ describe('Select', () => { text: true, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -208,6 +261,7 @@ describe('Select', () => { select: { unnamedTabText: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -223,6 +277,7 @@ describe('Select', () => { select: { array: {}, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -238,6 +293,7 @@ describe('Select', () => { select: { array: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -255,6 +311,7 @@ describe('Select', () => { text: true, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -273,6 +330,7 @@ describe('Select', () => { select: { blocks: {}, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -288,6 +346,7 @@ describe('Select', () => { select: { blocks: true, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -305,6 +364,7 @@ describe('Select', () => { cta: true, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -330,6 +390,7 @@ describe('Select', () => { cta: { ctaText: true }, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -372,6 +433,7 @@ describe('Select', () => { select: { text: false, }, + depth: 0, }) const expected = { ...post } @@ -388,6 +450,7 @@ describe('Select', () => { select: { number: false, }, + depth: 0, }) const expected = { ...post } @@ -404,6 +467,7 @@ describe('Select', () => { select: { select: false, }, + depth: 0, }) const expected = { ...post } @@ -420,6 +484,7 @@ describe('Select', () => { select: { selectMany: false, }, + depth: 0, }) const expected = { ...post } @@ -437,6 +502,7 @@ describe('Select', () => { number: false, text: false, }, + depth: 0, }) const expected = { ...post } @@ -447,6 +513,29 @@ describe('Select', () => { expect(res).toStrictEqual(expected) }) + it('should exclude relationships', async () => { + const res = await payload.findByID({ + collection: 'posts', + id: postId, + select: { + hasOne: false, + hasMany: false, + hasManyPoly: false, + hasOnePoly: false, + }, + depth: 0, + }) + + const expected = { ...post } + + delete expected['hasOne'] + delete expected['hasMany'] + delete expected['hasManyPoly'] + delete expected['hasOnePoly'] + + expect(res).toStrictEqual(expected) + }) + it('should exclude group', async () => { const res = await payload.findByID({ collection: 'posts', @@ -454,6 +543,7 @@ describe('Select', () => { select: { group: false, }, + depth: 0, }) const expected = { ...post } @@ -472,6 +562,7 @@ describe('Select', () => { text: false, }, }, + depth: 0, }) const expected = deepCopyObject(post) @@ -488,6 +579,7 @@ describe('Select', () => { select: { array: false, }, + depth: 0, }) const expected = { ...post } @@ -506,6 +598,7 @@ describe('Select', () => { text: false, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -524,6 +617,7 @@ describe('Select', () => { select: { blocks: false, }, + depth: 0, }) const expected = { ...post } @@ -542,6 +636,7 @@ describe('Select', () => { cta: false, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -562,6 +657,7 @@ describe('Select', () => { cta: { ctaText: false }, }, }, + depth: 0, }) expect(res).toStrictEqual({ @@ -1630,6 +1726,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { text: true, } satisfies Config['collectionsSelect']['posts'], @@ -1647,6 +1744,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { number: true, text: true, @@ -1666,6 +1764,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { group: true, } satisfies Config['collectionsSelect']['posts'], @@ -1683,6 +1782,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { group: { text: true }, } satisfies Config['collectionsSelect']['posts'], @@ -1704,6 +1804,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { text: false, } satisfies Config['collectionsSelect']['posts'], @@ -1722,6 +1823,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { number: false, } satisfies Config['collectionsSelect']['posts'], @@ -1740,6 +1842,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { number: false, text: false, @@ -1760,6 +1863,7 @@ describe('Select', () => { const res = await restClient .GET(`/posts/${postId}`, { query: { + depth: 0, select: { group: { text: false, @@ -2129,7 +2233,19 @@ describe('Select', () => { }) }) -function createPost() { +async function createPost() { + const upload = await payload.create({ + collection: 'upload', + data: {}, + filePath: path.resolve(dirname, 'image.jpg'), + }) + + const relation = await payload.create({ + depth: 0, + collection: 'rels', + data: {}, + }) + return payload.create({ collection: 'posts', depth: 0, @@ -2142,6 +2258,11 @@ function createPost() { number: 1, text: 'text', }, + hasMany: [relation], + hasManyUpload: [upload], + hasOne: relation, + hasManyPoly: [{ relationTo: 'rels', value: relation }], + hasOnePoly: { relationTo: 'rels', value: relation }, blocks: [ { blockType: 'cta', diff --git a/test/select/payload-types.ts b/test/select/payload-types.ts index 9d6c7ca08cf..7b5004d5d1f 100644 --- a/test/select/payload-types.ts +++ b/test/select/payload-types.ts @@ -17,6 +17,8 @@ export interface Config { 'deep-posts': DeepPost; pages: Page; points: Point; + upload: Upload; + rels: Rel; users: User; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; @@ -30,6 +32,8 @@ export interface Config { 'deep-posts': DeepPostsSelect | DeepPostsSelect; pages: PagesSelect | PagesSelect; points: PointsSelect | PointsSelect; + upload: UploadSelect | UploadSelect; + rels: RelsSelect | RelsSelect; users: UsersSelect | UsersSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; @@ -116,6 +120,28 @@ export interface Post { }; unnamedTabText?: string | null; unnamedTabNumber?: number | null; + hasOne?: (string | null) | Rel; + hasMany?: (string | Rel)[] | null; + hasManyUpload?: (string | Rel)[] | null; + hasOnePoly?: { + relationTo: 'rels'; + value: string | Rel; + } | null; + hasManyPoly?: + | { + relationTo: 'rels'; + value: string | Rel; + }[] + | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "rels". + */ +export interface Rel { + id: string; updatedAt: string; createdAt: string; } @@ -343,6 +369,24 @@ export interface Point { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "upload". + */ +export interface Upload { + id: string; + updatedAt: string; + createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users". @@ -391,6 +435,14 @@ export interface PayloadLockedDocument { relationTo: 'points'; value: string | Point; } | null) + | ({ + relationTo: 'upload'; + value: string | Upload; + } | null) + | ({ + relationTo: 'rels'; + value: string | Rel; + } | null) | ({ relationTo: 'users'; value: string | User; @@ -487,6 +539,11 @@ export interface PostsSelect { }; unnamedTabText?: T; unnamedTabNumber?: T; + hasOne?: T; + hasMany?: T; + hasManyUpload?: T; + hasOnePoly?: T; + hasManyPoly?: T; updatedAt?: T; createdAt?: T; } @@ -705,6 +762,31 @@ export interface PointsSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "upload_select". + */ +export interface UploadSelect { + updatedAt?: T; + createdAt?: T; + url?: T; + thumbnailURL?: T; + filename?: T; + mimeType?: T; + filesize?: T; + width?: T; + height?: T; + focalX?: T; + focalY?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "rels_select". + */ +export interface RelsSelect { + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users_select".