We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
One of the best ways of doing a many-to-many relationship is something like this:
model Bli {...} model Bla { has $!id is serial; has $.a is column; has @.bles is relationship( *.bla-id, :model<Ble>); method blis { self.bles.join-model(Bli, *.bli-id == *.id) } } model Ble { has $.bla-id is column{ :id, :references{ .id }, :model-name<Bla> }; has $.bli-id is column{ :id, :references{ .id }, :model-name<Bli> }; } model Bli { has $!id is serial; has $.i is column; has @.bles is relationship( *.ble-id, :model<Ble>); method blas { self.bles.join-model(Bla, *.bla-id == *.id) } } red-defaults "SQLite"; schema(Bla, Ble, Bli).create; Bla.^create: :a<bla1>; Bli.^create: :i<bli1>; Ble.^create: :1bla-id, :1bli-id; .say for Bla.^load(1).blis
But that has some problems, for example, it's not so easy to create new objects, so I think it should be improved. Maybe something like this:
model Bla { has $!id is serial; has $.a is column; has @.bles is relationship( *.bla-id, :model<Ble>); has @.blis is relationship( *.bli-id, :many-to-many{ .bles }, :model<Bli> ); } model Ble { has $.bla-id is column{ :id, :references{ .id }, :model-name<Bla> }; has $.bli-id is column{ :id, :references{ .id }, :model-name<Bli> }; has $.bla is relationship(*.bla-id, :model<Bla>); has $.bli is relationship(*.bli-id, :model<Bli>); } model Bli { has $!id is serial; has $.i is column; has @.bles is relationship( *.ble-id, :model<Ble>); has @.blas is relationship( *.bla-id, :many-to-many{ .bles }, :model<Bla> ); }
But I'm not sure about that syntax. The important part is the @ sigil and some way of specifying 2 model/key pairs.
Something that should be defined is that we should use an intermediate to-many relationship:
has @.blis is relationship( *.bli-id, :many-to-many{ .bles }, :model<Bli> );
Or if we should specify 2 relationships:
has @.blis is relationship( :many{ .bles }, :to-many{ .bli } );
Or 2 pairs of column/model:
has @.blis is relationship( *.bli-id, :model<Bli>, :intermediate{ .bla-id }, :intermediate-model<Ble> );
Any suggestions?
The text was updated successfully, but these errors were encountered:
maybe all should be accepted (with a more consistent syntax)
Sorry, something went wrong.
It's easily done with $post.post-tags>>.tag, so no need for special syntax.
$post.post-tags>>.tag
No branches or pull requests
One of the best ways of doing a many-to-many relationship is something like this:
But that has some problems, for example, it's not so easy to create new objects, so I think it should be improved.
Maybe something like this:
But I'm not sure about that syntax. The important part is the @ sigil and some way of specifying 2 model/key pairs.
Something that should be defined is that we should use an intermediate to-many relationship:
Or if we should specify 2 relationships:
Or 2 pairs of column/model:
Any suggestions?
The text was updated successfully, but these errors were encountered: