feat: .^create on belongs-to relationship with auto FK#596
Open
hermes-fco wants to merge 4 commits into
Open
Conversation
added 2 commits
June 11, 2026 14:41
Port from PR FCO#523 (2021): 1. Fix ast-value .ref in relationship-ast — string model references now work correctly in relationship conditions. (Red::AST::Eq.new: $\_, ast-value .ref: $t2) 2. Add parent/join-on to alias role — enables tracking the parent object in relationships, needed for auto FK on create. 3. Enhance .^create to handle relationship accessors: when called via $ble.bla.^create(...), automatically sets the foreign key on the parent object and saves it. 4. Tests: belongs-to create with auto FK, isolation between instances. Closes FCO#523
- String model references (:model<Name>) - Type model references (:model(Type)) - has-one create via relationship accessor - Multiple creates on same parent - Create with FK already set - Isolation between parent instances - Extra attributes passthrough - Unsaved parent error case - FK default=0 edge case - To-many .create regression checks
FCO
reviewed
Jun 11, 2026
| #| And Lists and/or Hashes for relationships | ||
| multi method create(\model where *.DEFINITE, *%orig-pars, :$with where not .defined) is hidden-from-backtrace is rw { | ||
| die "Cannot call .^create on a defined model." if model.DEFINITE; | ||
| multi method create(\\mo where *.DEFINITE, *%orig-pars, :$with where not .defined) is hidden-from-backtrace is rw { |
Author
There was a problem hiding this comment.
Verdade! Era escaping bug — o arquivo ficou com 4 barras em vez de 1. Corrigido em 2ff9196.
| multi method create(\model where *.DEFINITE, *%orig-pars, :$with where not .defined) is hidden-from-backtrace is rw { | ||
| die "Cannot call .^create on a defined model." if model.DEFINITE; | ||
| multi method create(\\mo where *.DEFINITE, *%orig-pars, :$with where not .defined) is hidden-from-backtrace is rw { | ||
| my \\model = mo.^orig; |
Author
There was a problem hiding this comment.
Mesmo problema de escaping. Corrigido junto.
added 2 commits
June 11, 2026 15:53
…e expected)
- t/35-create.rakutest: :default(0) → :default{ 0 } fixes 'Type check failed in assignment to &!default'
- lib/Red/Column.rakumod: .perl() → .raku()
- lib/Red/Model.rakumod: .get_value(self).perl → .get_value(self).raku
- lib/X/Red/Exceptions.rakumod: $.orig-exception.perl → $.orig-exception.raku
- lib/Red/Driver/Mock.rakumod: $re.perl() → $re.raku()
- lib/Red/Cli.rakumod: %pars.map(*.perl) → %pars.map(*.raku)
- lib/Red/Driver.rakumod: @bind.perl()/@binds.perl() → @bind.raku()/@binds.raku()
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.
What
Port and fix of PR #523 (from 2021).
Enables calling
.^createdirectly on a belongs-to relationship accessor, with automatic foreign key management:Changes
1. Fix:
ast-value .refin relationship-astString model references now work correctly (
Red::AST::Eq.new: $_, ast-value .ref: $t2)2. Add
parent/join-onto alias roleEnables tracking the parent object for FK auto-set during create.
3. Enhance
.^createmetamodel methodWhen invoked on a relationship alias (has
join-on+parent), creates the related object and automatically sets the FK on the parent, then saves it.4. Tests
Files
lib/MetamodelX/Red/Model.rakumod— create method + alias rolelib/Red/Attr/Relationship.rakumod— ast-value fixt/35-create.rakutest— new testsCloses #523