Add RefersToMorphed relation attribute#123
Conversation
Add the #[RefersToMorphed] (and @RefersToMorphed) attribute, the morphed counterpart of RefersTo, mirroring BelongsToMorphed. It compiles to the `refersToMorphed` relation type and allows self-linked / cyclic morphed references that BelongsToMorphed cannot persist in a single transaction. Adds functional tests across all four drivers verifying the relation is generated as Relation::REFERS_TO_MORPHED with the morph and inner key columns. Requires cycle/orm with Relation::REFERS_TO_MORPHED and cycle/schema-builder with the `refersToMorphed` schema generator.
Add the #[RefersToMorphed] IDE metadata (relations.meta-storm.xml) mirroring BelongsToMorphed, and require cycle/orm ^2.18 and cycle/schema-builder ^2.12 which ship the REFERS_TO_MORPHED relation type the attribute compiles to.
Suppress the same DeprecatedClass (NamedArgumentConstructor) and InvalidClassConstantType (TYPE) issues already baselined for the sibling relation annotations. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.x #123 +/- ##
============================================
+ Coverage 91.90% 91.93% +0.02%
- Complexity 329 330 +1
============================================
Files 38 39 +1
Lines 840 843 +3
============================================
+ Hits 772 775 +3
Misses 68 68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a new morphed relation attribute #[RefersToMorphed] (and @RefersToMorphed) to generate Cycle ORM relations of type Relation::REFERS_TO_MORPHED, enabling deferred/self-referential morphed references. Includes new functional tests (per driver) plus fixtures to validate the generated relation type and expected morph/inner key columns, and bumps required package versions to pick up the underlying ORM/schema-builder support.
Changes:
- Introduces
Cycle\Annotated\Annotation\Relation\Morphed\RefersToMorphedrelation attribute/annotation. - Adds cross-driver functional coverage + fixtures to assert the compiled schema produces
REFERS_TO_MORPHEDwith*_idand*_rolecolumns. - Updates PhpStorm meta-storm relations metadata and bumps composer dependency constraints.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Annotation/Relation/Morphed/RefersToMorphed.php |
Adds the new morphed relation attribute/annotation class compiling to refersToMorphed. |
tests/Annotated/Functional/Driver/Common/Relation/Morphed/RefersToMorphedTestCase.php |
Common functional assertion that the schema contains a REFERS_TO_MORPHED relation and expected columns. |
tests/Annotated/Functional/Driver/MySQL/Relation/Morphed/RefersToMorphedTest.php |
MySQL driver wrapper for the common test case. |
tests/Annotated/Functional/Driver/Postgres/Relation/Morphed/RefersToMorphedTest.php |
Postgres driver wrapper for the common test case. |
tests/Annotated/Functional/Driver/SQLite/Relation/Morphed/RefersToMorphedTest.php |
SQLite driver wrapper for the common test case. |
tests/Annotated/Functional/Driver/SQLServer/Relation/Morphed/RefersToMorphedTest.php |
SQLServer driver wrapper for the common test case. |
tests/Annotated/Fixtures/RefersToMorphed/Comment.php |
Fixture entity defining the RefersToMorphed relation. |
tests/Annotated/Fixtures/RefersToMorphed/Post.php |
Fixture entity implementing the morphed parent interface. |
tests/Annotated/Fixtures/RefersToMorphed/MorphedParentInterface.php |
Fixture interface used as the morphed target contract. |
resources/relations.meta-storm.xml |
Adds PhpStorm meta-storm constructor argument hints for RefersToMorphed. |
composer.json |
Updates dependency constraints to versions expected to support REFERS_TO_MORPHED and related generators. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The meta-storm `argument` attribute is the 0-based constructor parameter position (confirmed by the docs and the ManyToMany mapping). The morphed constructor is (target, cascade, nullable, innerKey, outerKey, ...), so the correct indexes are target=0, innerKey=3, outerKey=4 - not the 1/1/2 that were mirrored from the (buggy) sibling morphed entries. Without this, the IDE would offer entity completion for the `cascade`/`nullable` parameters instead of `target`/`innerKey`/`outerKey`. Addresses the Copilot review comment on PR #123. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
BelongsToMorphed, MorphedHasOne and MorphedHasMany had the same incorrect meta-storm argument indexes as RefersToMorphed: target/innerKey/outerKey were mapped to 1/1/2 while the morphed constructor is (target, cascade, nullable, innerKey, outerKey, ...), i.e. positions 0/3/4. Align all four morphed relations so the IDE offers entity completion for the target and column completion for the real innerKey/outerKey arguments.
14a398e to
a5aa920
Compare
Add the #[RefersToMorphed] (and @RefersToMorphed) attribute, the morphed
counterpart of RefersTo, mirroring BelongsToMorphed. It compiles to the
refersToMorphedrelation type and allows self-linked / cyclic morphedreferences that BelongsToMorphed cannot persist in a single transaction.
Adds functional tests across all four drivers verifying the relation is
generated as Relation::REFERS_TO_MORPHED with the morph and inner key columns.
Requires cycle/orm with Relation::REFERS_TO_MORPHED and cycle/schema-builder
with the
refersToMorphedschema generator.