Skip to content

Instantly share code, notes, and snippets.

@Altreus
Created May 26, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Altreus/7007e0eefa0e21942a6fd2d0c6d72213 to your computer and use it in GitHub Desktop.
Save Altreus/7007e0eefa0e21942a6fd2d0c6d72213 to your computer and use it in GitHub Desktop.
use Red;
model Claim is rw is export {
has Str $.student-email is referencing{ :model<Student>, :column<email> };
has $.student is relationship({ .student-email }, :model<Student>);
has Int $.reward-id is referencing{ :model<Reward>, :column<id> };
has $.reward is relationship({ .reward-id }, :model<Reward>);
}
model Hootbox is rw is export {
has Int $.id is serial;
has Int $.reward is referencing{ :model<Reward>, :column<id> };
has Int $.level is column;
}
model Reward is rw is export {
has Int $.id is serial;
has Str $.name is column;
has Int $.cost is column;
has @.claims is relationship({.reward-id }, :model<Claim>);
}
model Student is rw is export {
has Str $.email is id;
has Str $.name is column;
has @.claims is relationship({ .student-id }, :model<Claim>);
method rewards { @.claims.map: *.reward }
}
sub deploy is export {
Reward.^create-table;
Student.^create-table;
Claim.^create-table;
Hootbox.^create-table;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment