-
-
Notifications
You must be signed in to change notification settings - Fork 27
CD sample
Fernando Correa de Oliveira edited this page Aug 16, 2018
·
12 revisions
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: { .id == $!cd-id };
has Artist $.artist = .^relates: { .id == CD.artist-id AND CD.id == $!cd-id };
}
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: { .id == $!artist-id };
has Track::ResultSeq $.tracks = .^relates: { .cd-id == $!id };
}
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 == $!id };
}