diff --git a/packages/next/src/views/List/handleGroupBy.ts b/packages/next/src/views/List/handleGroupBy.ts index f5f9700af..497d93a9e 100644 --- a/packages/next/src/views/List/handleGroupBy.ts +++ b/packages/next/src/views/List/handleGroupBy.ts @@ -144,6 +144,7 @@ export const handleGroupBy = async ({ if ( groupByField?.type === 'relationship' && + potentiallyPopulatedRelationship && typeof potentiallyPopulatedRelationship === 'object' ) { heading = diff --git a/test/group-by/e2e.spec.ts b/test/group-by/e2e.spec.ts index 201c5d066..716f88316 100644 --- a/test/group-by/e2e.spec.ts +++ b/test/group-by/e2e.spec.ts @@ -236,6 +236,26 @@ test.describe('Group By', () => { await expect(page.locator('.group-by-header')).toHaveCount(0) }) + test('should group by relationships even when their values are null', async () => { + await payload.create({ + collection: postsSlug, + data: { + title: 'My Post', + category: null, + }, + }) + + await page.goto(url.list) + + await addGroupBy(page, { fieldLabel: 'Category', fieldPath: 'category' }) + + await expect(page.locator('.table-wrap')).toHaveCount(3) + + await expect( + page.locator('.group-by-header__heading', { hasText: exactText('No value') }), + ).toBeVisible() + }) + test('should sort the group-by field globally', async () => { await page.goto(url.list)