Skip to content

Fix: skip relationship query when Repeater has no parent model#19906

Merged
danharrin merged 2 commits into
filamentphp:4.xfrom
FS-Baz:fix/repeater-no-query-without-parent-model
May 25, 2026
Merged

Fix: skip relationship query when Repeater has no parent model#19906
danharrin merged 2 commits into
filamentphp:4.xfrom
FS-Baz:fix/repeater-no-query-without-parent-model

Conversation

@FS-Baz
Copy link
Copy Markdown
Contributor

@FS-Baz FS-Baz commented May 25, 2026

Description

A Repeater with ->relationship() queries the related table on a Create page even though no parent model exists yet. getCachedExistingRecords() does not short-circuit when there is no model, so it runs select * from "posts" where "posts"."author_id" is null and "posts"."author_id" is not null — one redundant query per relationship Repeater per create-page render. Fixed by short-circuiting when there is no persisted model, mirroring EntanglesStateWithSingularRelationship which already guards with ! $record?->exists.

Reproduction: https://github.com/FS-Baz/filament-repeater-repro

Visual changes

None — internal behavior only, no UI change.

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@github-project-automation github-project-automation Bot moved this to Todo in Roadmap May 25, 2026
@danharrin danharrin added the bug Something isn't working label May 25, 2026
@danharrin danharrin added this to the v5 milestone May 25, 2026
@danharrin danharrin force-pushed the fix/repeater-no-query-without-parent-model branch from 0960832 to ee38eb1 Compare May 25, 2026 16:01
@danharrin danharrin changed the base branch from 5.x to 4.x May 25, 2026 16:01
@danharrin danharrin modified the milestones: v5, v4 May 25, 2026
@danharrin danharrin merged commit 7bd3a99 into filamentphp:4.x May 25, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Roadmap May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants