Skip to content

Commit 2ee3e30

Browse files
authored
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'` .
1 parent 61c5e0d commit 2ee3e30

File tree

6 files changed

+244
-2
lines changed

6 files changed

+244
-2
lines changed

packages/drizzle/src/find/traverseFields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ export const traverseFields = ({
526526

527527
if (
528528
!withTabledFields.rels &&
529-
field.type === 'relationship' &&
529+
(field.type === 'relationship' || field.type === 'upload') &&
530530
(field.hasMany || Array.isArray(field.relationTo))
531531
) {
532532
withTabledFields.rels = true

test/select/collections/Posts/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,33 @@ export const PostsCollection: CollectionConfig = {
116116
},
117117
],
118118
},
119+
{
120+
type: 'relationship',
121+
name: 'hasOne',
122+
relationTo: 'rels',
123+
},
124+
{
125+
type: 'relationship',
126+
name: 'hasMany',
127+
hasMany: true,
128+
relationTo: 'rels',
129+
},
130+
{
131+
type: 'upload',
132+
name: 'hasManyUpload',
133+
hasMany: true,
134+
relationTo: 'upload',
135+
},
136+
{
137+
type: 'relationship',
138+
name: 'hasOnePoly',
139+
relationTo: ['rels'],
140+
},
141+
{
142+
type: 'relationship',
143+
name: 'hasManyPoly',
144+
hasMany: true,
145+
relationTo: ['rels'],
146+
},
119147
],
120148
}

test/select/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ export default buildConfigWithDefaults({
2323
DeepPostsCollection,
2424
Pages,
2525
Points,
26+
{
27+
slug: 'upload',
28+
fields: [],
29+
upload: {
30+
staticDir: path.resolve(dirname, 'media'),
31+
},
32+
},
33+
{
34+
slug: 'rels',
35+
fields: [],
36+
},
2637
],
2738
globals: [
2839
{

test/select/image.jpg

84.1 KB
Loading

0 commit comments

Comments
 (0)