WiP: .^create from belongs-to relationship#523
Conversation
…CO/Red into create-to-one
…/Red into create-to-one
There was a problem hiding this comment.
Pull request overview
This PR attempts to make .^create work when invoked from a belongs-to (single) relationship where the referenced model is specified by string (e.g. :model<Bli>), by ensuring the relationship context (alias/join info + parent) is preserved so the FK can be propagated back to the owning row.
Changes:
- Adds new test coverage for creating records via single/belongs-to relationships (including type-based relationship declarations).
- Adjusts relationship/alias machinery so relationship selectors can carry a
parentreference and accept an explicit alias in join conditions. - Updates relationship AST generation and reference resolution to better handle aliasing.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
t/35-create.t |
Adds new subtests for create-from-relationship scenarios; reorders an existing array-create subtest. |
lib/Red/PrepareCode.pm6 |
Minor formatting/line-number-only change. |
lib/Red/Column.pm6 |
Tweaks ReferencesProxy.CALL-ME to treat definite aliases differently when resolving references. |
lib/Red/Attr/Relationship.pm6 |
Adjusts relationship AST generation to wrap RHS with ast-value. |
lib/MetamodelX/Red/Relationship.pm6 |
Changes scalar relationship accessor behavior to try to return a join alias with parent set. |
lib/MetamodelX/Red/Model.pm6 |
Modifies alias role to add parent and parameterize join-on with an alias argument. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| schema(Bla, Ble).drop.create; | ||
|
|
||
| # TODO: Figure out why this test can't be the last one | ||
| subtest "Create on has-one", { |
| is $bla.bles.head.gist, $ble.gist; | ||
| is $ble.bla.gist, $bla.gist; |
| is $ble.bla.gist, $bla.gist; | ||
| } | ||
|
|
||
| subtest "belogs-to using types", { |
| is $bli.blos.head.gist, $blo.gist; | ||
| is $blo.bli.gist, $bli.gist; |
| my role RAlias[Red::Model:U \rtype, Str $rname, \alias, \rel, \base, \join-type, @cols] { | ||
| method columns(|) { @cols } | ||
| method table(|) { rtype.^table } | ||
| method as(|) { self.table-formatter: $rname } | ||
| method orig(|) { rtype } | ||
| method join-type(|) { join-type } | ||
| method tables(|) { [ |base.^tables, alias ] } | ||
| method join-on(|) { | ||
| method parent(|) is rw { $ } | ||
| method columns(|) { @cols } |
| my \value = nqp::getattr(self, self.WHAT, $attr.name); | ||
| my $n = $self.WHAT."$name"(); | ||
| $n.^parent = self if $n.HOW.^can: "parent"; | ||
| return $n unless value; | ||
| value |
Code Review — PR #523 (WiP: .^create from belongs-to relationship)
🔍 Minor observations
💡 SuggestionClose this PR in favor of #596. If there are infrastructure changes here that weren't ported (the Reviewed by Hermes Agent |
Code Review —
|
| Metric | Value |
|---|---|
| Files changed | 237 (most from main merges) |
| Core lib files changed | ~10 |
| New lib features | has-one .^create, model-type referencing, attribute reuse fix, alias cache, Specialisable |
| New tests | 12 test files |
| Security scan | Clean |
Reviewed by Hermes Agent
Code Review — WiP: .^create from belongs-to relationshipVerdict: Comment (0 critical, 0 warnings, 4 suggestions) Early WiP implementing ✅ Looks Good
💡 Suggestions
🔍 Minor observations
📊 Stats
Reviewed by Hermes Agent |
Code Review — WiP: .^create from belongs-to relationshipVerdict: Comment (0 critical, 1 warning, 3 suggestions) This PR adds ✅ Looks Good
|
| Metric | Value |
|---|---|
| Files changed | 6 |
| Lines added | +118 |
| Lines removed | −28 |
| New tests | 3 subtests in t/35-create.t |
| Security scan | Clean |
Reviewed by Hermes Agent
🤖 Hermes Code Review — PR #523Summary: FCO's WiP: ✅ Looks Good
|
This is not working when using strings as referencing's model (but works if use the actual type)