Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A column being both pk and fk will raise error. #449

Closed
xinminglai opened this issue Oct 31, 2020 · 2 comments
Closed

A column being both pk and fk will raise error. #449

xinminglai opened this issue Oct 31, 2020 · 2 comments

Comments

@xinminglai
Copy link
Contributor

Below example code will raise error:

Type check failed in assignment to $!right; expected Red::AST but got Slip (Empty)
in method new at /opt/rakudo/share/perl6/site/sources/C9350343A71D40EA1AD797EAE41FF4033DE1D942 (Red::AST::Infix) line 25
in method relationship-ast at /opt/rakudo/share/perl6/site/sources/5B590052F4BF0EE76C3AD47F0924399022200F06 (Red::Attr::Relationship) line 115
in block at /opt/rakudo/share/perl6/site/sources/A7D03B9351A22E38BD993AFC9540FC31CB15D193 (MetamodelX::Red::Model) line 243
in method join-on at /opt/rakudo/share/perl6/site/sources/A7D03B9351A22E38BD993AFC9540FC31CB15D193 (MetamodelX::Red::Model) line 219
in block at /opt/rakudo/share/perl6/site/sources/0CE2BEE5D75F567587DF41AB96CF355DEE1C04B4 (Red::Driver::CommonSQL) line 372
in block at /opt/rakudo/share/perl6/site/sources/0CE2BEE5D75F567587DF41AB96CF355DEE1C04B4 (Red::Driver::CommonSQL) line 369
in method translate at /opt/rakudo/share/perl6/site/sources/0CE2BEE5D75F567587DF41AB96CF355DEE1C04B4 (Red::Driver::CommonSQL) line 355
in method prepare at /opt/rakudo/share/perl6/site/sources/0B9FDA4C1B7C1D06E6DC4ACC47C88D08C4AEF515 (Red::Driver) line 77
in submethod TWEAK at /opt/rakudo/share/perl6/site/sources/BE9C8AF8302236E807B04730E2C7B7243C17FE75 (Red::ResultSeq::Iterator) line 14
in method iterator at /opt/rakudo/share/perl6/site/sources/B9741F975EBBCC400F6E939A03452845E5AA24DD (Red::ResultSeq) line 89
in method Seq at /opt/rakudo/share/perl6/site/sources/B9741F975EBBCC400F6E939A03452845E5AA24DD (Red::ResultSeq) line 95
in method do-it at /opt/rakudo/share/perl6/site/sources/B9741F975EBBCC400F6E939A03452845E5AA24DD (Red::ResultSeq) line 100
in method head at /opt/rakudo/share/perl6/site/sources/B9741F975EBBCC400F6E939A03452845E5AA24DD (Red::ResultSeq) line 308
in method load at /opt/rakudo/share/perl6/site/sources/A7D03B9351A22E38BD993AFC9540FC31CB15D193 (MetamodelX::Red::Model) line 560

example.raku

use Red:api<2>;

model A is table {
has Int $.id is serial;
has Str $.name is column;
}

model B is table {
has Int $.a-id is column{ :id, :referencing(*.a-id, :model) };
has A $.a is relationship{ .a-id };
has Str $.name is column;
}

red-defaults default => database 'SQLite';

schema(A, B).create;

my $a = A.^create: :name('A');
B.^load: :a-id($a.id);

@FCO
Copy link
Owner

FCO commented Oct 31, 2020

As discussed on IRC, the code was wrong, right? @xinminglai would you mind posting the working code here, please?
Anyway, this error is at least LTA. I need to fix that. Thanks

@xinminglai
Copy link
Contributor Author

Hi, This is modified version, Which works perfectly. So, We can safely close this bug, And I'll send a patch for cookbook

use Red:api<2>;

model B { ... }

model A is table<aa> {
    has Int $.id is serial;
    has Str $.name is column;
}

model B is table<bb> {
    has Int $.a-id is column{ :id, :references{.id}, :model-name<A>, };
    has A $.a is relationship{ .a-id };
    has Str $.name is column;
}

red-defaults default => database 'SQLite';

schema(A, B).create;

my $a = A.^create: :name('A');
B.^create: :a-id($a.id), :name('b');
my $b = B.^load: :a-id($a.id);
$b.raku.say;

@FCO FCO closed this as completed Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants