Skip to content

Computed fields on repositories, batched or not - #320

Merged
TomHAnderson merged 1 commit into
API-Skeletons:14.1.xfrom
TomHAnderson:feature/repository-computed-fields
Oct 6, 2026
Merged

TomHAnderson merged 1 commit into
API-Skeletons:14.1.xfrom
TomHAnderson:feature/repository-computed-fields

Conversation

@TomHAnderson

Copy link
Copy Markdown
Member

A #[ComputedField] may be on a method of the entity's repository, which is given the entity first and is called on the repository the entity manager gives, so a custom repository factory is honoured. Its further parameters are the field's arguments.

With batch: true the method is given a Collection of every entity waiting for the field with the same arguments, keyed by the database value of their identifier, and returns their values keyed the same way, so one query computes them all.

  • Resolve\ComputedFieldBatchLoader groups entities by exposed class, field and arguments and calls the method once per group, at most 1000 entities a call. A missing value is null; a method returning neither an array nor a Collection is an error of every entity's field.
  • Batched fields may be of an entity type and a list; with batchAssociations off each entity is given alone; extract() leaves batched fields out.
  • When the metadata is built: the first parameter must accept the entity, or any Collection for a batch; batch is rejected on an entity's method and for a composite or association identifier.
  • Doctrine gives an entity its parent's repository only from a mapped superclass, so an exposed subclass lacking a repository field of its exposed parent throws rather than resolving it as null.
  • Two computed fields of one name throw, rather than one silently replacing the other.
  • Metadata records repository and batch, left out when unset.

A #[ComputedField] may be on a method of the entity's repository, which
is given the entity first and is called on the repository the entity
manager gives, so a custom repository factory is honoured.  Its further
parameters are the field's arguments.

With batch: true the method is given a Collection of every entity
waiting for the field with the same arguments, keyed by the database
value of their identifier, and returns their values keyed the same way,
so one query computes them all.

- Resolve\ComputedFieldBatchLoader groups entities by exposed class,
  field and arguments and calls the method once per group, at most 1000
  entities a call.  A missing value is null; a method returning neither
  an array nor a Collection is an error of every entity's field.
- Batched fields may be of an entity type and a list; with
  batchAssociations off each entity is given alone; extract() leaves
  batched fields out.
- When the metadata is built: the first parameter must accept the
  entity, or any Collection for a batch; batch is rejected on an entity's
  method and for a composite or association identifier.
- Doctrine gives an entity its parent's repository only from a mapped
  superclass, so an exposed subclass lacking a repository field of its
  exposed parent throws rather than resolving it as null.
- Two computed fields of one name throw, rather than one silently
  replacing the other.
- Metadata records repository and batch, left out when unset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b55caff) to head (280723d).
⚠️ Report is 1 commits behind head on 14.1.x.

Additional details and impacted files
@@             Coverage Diff              @@
##              14.1.x      #320    +/-   ##
============================================
  Coverage     100.00%   100.00%            
- Complexity      1318      1396    +78     
============================================
  Files             81        83     +2     
  Lines           3597      3796   +199     
============================================
+ Hits            3597      3796   +199     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TomHAnderson
TomHAnderson merged commit 016fcb6 into API-Skeletons:14.1.x Oct 6, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant