Conversation
Tigrov
commented
Mar 16, 2026
| Q | A |
|---|---|
| Is bugfix? | ✔️/❌ |
| New feature? | ✔️ |
| Breaks BC? | ✔️ |
| Fixed issues |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #546 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 655 657 +2
===========================================
Files 43 43
Lines 1629 1631 +2
===========================================
+ Hits 1629 1631 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new ActiveRecord::instantiate() static method that uses ReflectionClass::newInstanceWithoutConstructor() to create ActiveRecord instances without invoking the constructor. This removes the previous limitation where ActiveRecord models with required constructor parameters couldn't be used with ActiveRecord::query(), RepositoryTrait, or relations that reference class names.
Changes:
- Added
instantiate()toActiveRecordInterfaceand implemented it inAbstractActiveRecordusing reflection to bypass the constructor - Updated
ActiveQueryconstructor andEventsTrait::query()to useinstantiate()instead ofnew $modelClass() - Updated tests from expecting
ArgumentCountErrorto asserting successful query/relation behavior, and updated documentation to reflect the new behavior
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/ActiveRecordInterface.php | Added instantiate(): static method to the interface |
| src/AbstractActiveRecord.php | Default implementation using ReflectionClass::newInstanceWithoutConstructor() |
| src/ActiveQuery.php | Changed constructor to use $modelClass::instantiate() instead of new $modelClass() |
| src/Trait/EventsTrait.php | Changed query() to use instantiate() instead of direct construction |
| tests/ActiveRecordTest.php | Updated tests to verify constructors with required params now work with queries/relations |
| docs/create-model.md | Replaced limitations section with a note about constructor not being called |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.