Skip to content

Commit

Permalink
fix(db-postgres): select query on upload fields with hasMany: true (
Browse files Browse the repository at this point in the history
#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'` .
  • Loading branch information
r1tsuu authored Dec 18, 2024
1 parent 61c5e0d commit 2ee3e30
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/drizzle/src/find/traverseFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/select/collections/Posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
],
}
11 changes: 11 additions & 0 deletions test/select/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export default buildConfigWithDefaults({
DeepPostsCollection,
Pages,
Points,
{
slug: 'upload',
fields: [],
upload: {
staticDir: path.resolve(dirname, 'media'),
},
},
{
slug: 'rels',
fields: [],
},
],
globals: [
{
Expand Down
Binary file added test/select/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2ee3e30

Please sign in to comment.