Skip to content

Conversation

@JanTvrdik
Copy link
Member

Summary

  • Adds a new optional readOnly parameter to the preload() method
  • When readOnly: true, applies Query::HINT_READ_ONLY to inner queries
  • Explicitly marks preloaded entities as read-only in the UnitOfWork
  • Improves performance for read-only operations by disabling change tracking

Usage

// Normal preload (entities are tracked for changes)
$preloader->preload($articles, 'category');

// Read-only preload (entities are not tracked for changes)
$preloader->preload($articles, 'category', readOnly: true);

Closes #36

Test plan

  • Added tests for many-to-one associations (testManyHasOneWithPreloadReadOnly)
  • Added tests for one-to-many associations (testOneHasManyWithPreloadReadOnly)
  • Added tests for many-to-many associations (testManyHasManyWithPreloadReadOnly)
  • All 252 tests pass
  • PHPStan reports no errors

Copy link
Member

@janedbal janedbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing readme mention.

Adds support for setting Query::HINT_READ_ONLY on inner queries
via a new optional `readOnly` parameter on the preload() method.

When enabled, preloaded entities are marked as read-only in the
UnitOfWork, improving performance for read-only operations by
disabling change tracking.

Closes #36
@JanTvrdik JanTvrdik force-pushed the feature/readonly-queries branch from 9162ffb to c3c6892 Compare December 15, 2025 16:38
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.

Support readonly queries

3 participants