Repository navigation
Computed fields on repositories, batched or not - #320
Merged
TomHAnderson merged 1 commit intoOct 6, 2026
Merged
TomHAnderson merged 1 commit into
TomHAnderson merged 1 commit into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.