Skip to content

Commit 1f15498

Browse files
committed
chore: add test for issue #9171
1 parent 2025702 commit 1f15498

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

test/relationships/config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ export default buildConfigWithDefaults({
8484
type: 'relationship',
8585
relationTo: relationSlug,
8686
},
87+
{
88+
name: 'blocks',
89+
type: 'blocks',
90+
blocks: [
91+
{
92+
slug: 'block',
93+
fields: [
94+
{
95+
name: 'relationField',
96+
type: 'relationship',
97+
relationTo: relationSlug,
98+
},
99+
],
100+
},
101+
],
102+
},
87103
// Relationship w/ default access
88104
{
89105
name: 'defaultAccessRelation',

test/relationships/int.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,35 @@ describe('Relationships', () => {
334334
expect(query.docs).toHaveLength(1) // Due to limit: 1
335335
})
336336

337+
it('should allow querying within blocks', async () => {
338+
const rel = await payload.create({
339+
collection: relationSlug,
340+
data: {
341+
name: 'test',
342+
disableRelation: false,
343+
},
344+
})
345+
346+
const doc = await payload.create({
347+
collection: slug,
348+
data: {
349+
blocks: [
350+
{
351+
blockType: 'block',
352+
relationField: rel.id,
353+
},
354+
],
355+
},
356+
})
357+
358+
const { docs } = await payload.find({
359+
collection: slug,
360+
where: { 'blocks.relationField': { equals: rel.id } },
361+
})
362+
363+
expect(docs[0].id).toBe(doc.id)
364+
})
365+
337366
describe('Custom ID', () => {
338367
it('should query a custom id relation', async () => {
339368
const { customIdRelation } = await restClient

test/relationships/payload-types.ts

+19
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export interface Post {
9797
description?: string | null;
9898
number?: number | null;
9999
relationField?: (string | null) | Relation;
100+
blocks?:
101+
| {
102+
relationField?: (string | null) | Relation;
103+
id?: string | null;
104+
blockName?: string | null;
105+
blockType: 'block';
106+
}[]
107+
| null;
100108
defaultAccessRelation?: (string | null) | StrictAccess;
101109
chainedRelation?: (string | null) | Chained;
102110
maxDepthRelation?: (string | null) | Relation;
@@ -429,6 +437,17 @@ export interface PostsSelect<T extends boolean = true> {
429437
description?: T;
430438
number?: T;
431439
relationField?: T;
440+
blocks?:
441+
| T
442+
| {
443+
block?:
444+
| T
445+
| {
446+
relationField?: T;
447+
id?: T;
448+
blockName?: T;
449+
};
450+
};
432451
defaultAccessRelation?: T;
433452
chainedRelation?: T;
434453
maxDepthRelation?: T;

0 commit comments

Comments
 (0)