WiP: .^create from belongs-to relationship#523
Open
FCO wants to merge 5 commits into
Open
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", { |
Comment on lines
+32
to
+33
| is $bla.bles.head.gist, $ble.gist; | ||
| is $ble.bla.gist, $bla.gist; |
| is $ble.bla.gist, $bla.gist; | ||
| } | ||
|
|
||
| subtest "belogs-to using types", { |
Comment on lines
+56
to
+57
| is $bli.blos.head.gist, $blo.gist; | ||
| is $blo.bli.gist, $bli.gist; |
Comment on lines
225
to
+227
| 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 } |
Comment on lines
+163
to
+167
| 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 |
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.
This is not working when using strings as referencing's model (but works if use the actual type)