Skip to content

Commit 3a65784

Browse files
authored
fix(db-postgres): query hasMany text/number in array/blocks (#8003)
## Description Fixes #7671 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes
1 parent 8212c0d commit 3a65784

File tree

6 files changed

+397
-5
lines changed

6 files changed

+397
-5
lines changed

packages/drizzle/src/queries/getTableColumnFromPath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ export const getTableColumnFromPath = ({
257257
tableType = 'numbers'
258258
columnName = 'number'
259259
}
260-
newTableName = `${tableName}_${tableType}`
260+
newTableName = `${rootTableName}_${tableType}`
261261
const joinConstraints = [
262-
eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
263-
eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),
262+
eq(adapter.tables[rootTableName].id, adapter.tables[newTableName].parent),
263+
like(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),
264264
]
265265

266266
if (locale && field.localized && adapter.payload.config.localization) {

test/buildConfigWithDefaults.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
IndentFeature,
1111
InlineCodeFeature,
1212
ItalicFeature,
13+
lexicalEditor,
1314
LinkFeature,
1415
OrderedListFeature,
1516
ParagraphFeature,
@@ -21,7 +22,6 @@ import {
2122
UnderlineFeature,
2223
UnorderedListFeature,
2324
UploadFeature,
24-
lexicalEditor,
2525
} from '@payloadcms/richtext-lexical'
2626
// import { slateEditor } from '@payloadcms/richtext-slate'
2727
import { buildConfig } from 'payload'
@@ -164,7 +164,9 @@ export async function buildConfigWithDefaults(
164164
}
165165

166166
if (process.env.PAYLOAD_DISABLE_ADMIN === 'true') {
167-
if (typeof config.admin !== 'object') config.admin = {}
167+
if (typeof config.admin !== 'object') {
168+
config.admin = {}
169+
}
168170
config.admin.disable = true
169171
}
170172

test/fields/collections/Number/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ const NumberFields: CollectionConfig = {
7979
hasMany: true,
8080
minRows: 2,
8181
},
82+
{
83+
name: 'array',
84+
type: 'array',
85+
fields: [
86+
{
87+
name: 'numbers',
88+
type: 'number',
89+
hasMany: true,
90+
},
91+
],
92+
},
93+
{
94+
name: 'blocks',
95+
type: 'blocks',
96+
blocks: [
97+
{
98+
slug: 'block',
99+
fields: [
100+
{
101+
name: 'numbers',
102+
type: 'number',
103+
hasMany: true,
104+
},
105+
],
106+
},
107+
],
108+
},
82109
],
83110
}
84111

test/fields/collections/Text/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ const TextFields: CollectionConfig = {
134134
disableListFilter: true,
135135
},
136136
},
137+
{
138+
name: 'array',
139+
type: 'array',
140+
fields: [
141+
{
142+
name: 'texts',
143+
type: 'text',
144+
hasMany: true,
145+
},
146+
],
147+
},
148+
{
149+
name: 'blocks',
150+
type: 'blocks',
151+
blocks: [
152+
{
153+
slug: 'block',
154+
fields: [
155+
{
156+
name: 'texts',
157+
type: 'text',
158+
hasMany: true,
159+
},
160+
],
161+
},
162+
],
163+
},
137164
],
138165
}
139166

0 commit comments

Comments
 (0)