http://qs1969.pair.com?node_id=11130406

tomgracey has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

So this is basic question about Raku. I am experimenting with it whilst having not the slightest clue what I'm doing. Just the module/package/class (which is it anyway?) loading system seems rather baffling. But I digress.

So here's the problem:

I have a basic schema file, which looks like this:

use Red; model User { has Int $!id is serial; has Str $.username is column is rw; has Str $.password is column is rw; has @.vmails is relationship(*.user_id, :model<Vmail>); } model Vmail { has Int $!id is serial; has Int $!user_id is referencing(*.id, :model<User>); has Str $.name is column; has $.user is relationship(*.id, :model<User>); }
And my script looks like this:
#!/usr/bin/raku use Red; use lib 'lib'; use Schema; my $*RED-DB = database "Pg", :user<vmail_user>, :dbname<vmail>, :passw +ord<--redacted-->; my $user = User.^create( username => 'Bill' ); print "*** DONE ***\n";
The database and tables exist in postgres (created manually rather than using Red) - and the table definitions are:
# \d user Table "public.user" Column | Type | Modifiers ----------+---------+------------------------------------------------- +-- id | integer | not null default nextval('user_id_seq'::regclass +) username | text | password | text | Indexes: "user_pkey" PRIMARY KEY, btree (id) Referenced by: TABLE "vmail" CONSTRAINT "vmail_user_id_fkey" FOREIGN KEY (user_id +) REFERENCES "user"(id) =# \d vmail Table "public.vmail" Column | Type | Modifiers ---------+---------+-------------------------------------------------- +-- id | integer | not null default nextval('vmail_id_seq'::regclass +) user_id | integer | name | text | Indexes: "vmail_pkey" PRIMARY KEY, btree (id) Foreign-key constraints: "vmail_user_id_fkey" FOREIGN KEY (user_id) REFERENCES "user"(id)
When I run the script I get the following output:
Could not find Vmail in: file#/var/www/apps/raku/vmail/lib inst#/root/.raku inst#/opt/rakudo-pkg/share/perl6/site inst#/opt/rakudo-pkg/share/perl6/vendor inst#/opt/rakudo-pkg/share/perl6/core ap# nqp# perl5# in block at /opt/rakudo-pkg/share/perl6/site/sources/9740DDE0E85E09 +3DCDF40F690C620BD9BAEE9078 (Red::Attr::Relationship) line 46 in method relationship-model at /opt/rakudo-pkg/share/perl6/site/sou +rces/9740DDE0E85E093DCDF40F690C620BD9BAEE9078 (Red::Attr::Relationshi +p) line 43 in method build-relationship at /opt/rakudo-pkg/share/perl6/site/sou +rces/9740DDE0E85E093DCDF40F690C620BD9BAEE9078 (Red::Attr::Relationshi +p) line 67 in method <anon> at /opt/rakudo-pkg/share/perl6/site/sources/C6C0BDE +B2D9A3E5141D8CD425806A5162AFE5DE9 (MetamodelX::Red::Relationship) lin +e 58 in method create at /opt/rakudo-pkg/share/perl6/site/sources/A963FC4 +C1C5D6923CAA0DC1451EE51EA254DA1ED (MetamodelX::Red::Model) line 483 in block <unit> at test_red.raku line 9

Hm... I don't think I am such a huge fan of the SHA-1 hashes...

Any idea why it can't find Vmail? I thought it might be related to the order of declaration of the model statements. I note that one of the examples (here: https://github.com/FCO/Red/blob/master/examples/alive/Schema.rakumod) seems to declare empty(?) models first and redeclare them later (to avoid referencing a model the that doesn't exist? Seems a bit ugly). I don't know if this has anything to do with it, but I tried adding model Vmail{...} at the top with no effect on the output

I only ever ask dumb questions and don't expect this to be any different...! But any help for a raku first-timer would be much appreciated.

Thanks!