Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain indirect relationships more clearly #163

Closed
Altreus opened this issue May 30, 2019 · 1 comment
Closed

Explain indirect relationships more clearly #163

Altreus opened this issue May 30, 2019 · 1 comment
Projects

Comments

@Altreus
Copy link
Contributor

Altreus commented May 30, 2019

It is unclear how indirect relationships (using :model<ModelName> to define them) are implemented, just from the examples.

I had an issue whereby my Red setup did not know how to find a model, because it was not in a file by that name:

# Schema.pm6
model A {
  has Int $.id is serial;
  has    @.rel is relationship({.a-id }, :model<B>);
}

model B {
  has Int $.id is serial;
  has Int $!b-id is referencing{ :model<B>, :column<id> };
}

The parameter :require<Schema> can be used to tell Red that it should load that module to find that relationship, but this can be cumbersome. A bigger example might be:

# lib/MyApp/Schema/A.pm6
model LongTableName {
  has Int $.id is serial;
  has    @.rel is relationship({.a-id }, :model<RealLongTableName>, :require<MyApp::Schema::RealLongTableName>);
}

A possible solution (I don't know whether this is feasible since I am still experimenting with Perl 6) would be to remember a model once it is declared; Red already makes use of global state, so this doesn't seem like a terrible option if it can be done. That way, you would only need to know how to find a :model if it hasn't been seen before, and the way to use Red would be to make sure all your models have been loaded before you do anything else.

@Altreus
Copy link
Contributor Author

Altreus commented May 31, 2019

Right - I misunderstood the meaning of $*RED-DB cos I'm still learning Perl6 as well :P

I think what I was about to propose is #7 - I would like this.

Altreus added a commit to Altreus/Red that referenced this issue May 31, 2019
@FCO FCO closed this as completed in 034d6a2 May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Documenting
Awaiting triage
Development

No branches or pull requests

1 participant