Allow for the composition of relations defined in roles.
The #80 and #84 provide for the composition of columns defined in roles, however it would equally useful to have relations defined in roles too.
So that something like:
model State { ... }
model Workflow is table('tinky_workflow') is rw {
has Int $.id is serial;
has Str $.name is column(:unique);
has State @.states is relationship({ .workflow-id });
}
role WithWorkflow {
has Int $.workflow-id is referencing( { Workflow.id });
has Workflow $.workflow is relationship({ .workflow-id });
}
model State is table('tinky_state') does WithWorkflow is rw {
has Int $.id is serial;
has Str $.name is column;
}
Would work.
As it currently stands the add-relationship being called in the trait code itself is happening too early as the role meta object doesn't have that method. I think the easiest way to do this is to add a new parametric role to the attribute in the traits and then have a compose-relationships that would be called in the model class compose which can enumerate those attributes and then call the add-relationship at that point.
A rakudo bug make it impossible to use those closures ({ Workflow.id } and { .workflow-id }). I have a patch that should make relationships on roles work, but I can’t test it because of this bug. https://github.com/rakudo/rakudo/issues/2619