-
-
Notifications
You must be signed in to change notification settings - Fork 27
CD sample
Fernando Correa de Oliveira edited this page Aug 18, 2018
·
12 revisions
This sample is based on DBIx::Class CD example and it's NOT working yet!!!
lib/Track.pm6
use Red;
model CD { ... }
model Artist { ... }
model Track {
has Uint $.id is column{ :id, :!nullable };
has Uint $.cd-id is referencing{ CD.id };
has Str $.title is column;
has CD $.cd = .^relates: { ::?CLASS.cd-id };
has Artist $.artist = $!cd.artist;
::?CLASS.^add-unique-constraint: { .cd-id, .title };
}
lib/CD.pm6
use Red;
use Track;
model Artist { ... }
model CD {
has UInt $.id is column{ :id, :!nullable };
has UInt $!artist-id is referencing{ Artist.id };
has Str $.title is column;
has UInt $.year is column;
has Artist $.artist = .^relates: { ::?CLASS.artist-id }, :prefetch;
has Track::ResultSeq $.tracks = .^relates: { .cd-id };
::?CLASS.^add-unique-constraint: { .artist-id, .title };
}
lib/Artist.pm6
use Red;
use CD;
model Artist {
has UInt $.id is column{ :id, :!nullable };
has Str $.name is column{ :unique, :!nullable };
has CD::ResultSeq $.cds = .^relates: { .artist-id };
}