-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
How to prefetch @. relationships? #417
Comments
I think the biggest problem is that the query will return multiple lines for each object... out or order... |
Maybe: model Book {
has UInt $!id is serial;
has Str $.name is column;
has UInt $!author-id is referencing(*.id, :model<Person>);
has $.author is relationship(*.author-id, :model<Person>);
}
model Person {
has UInt $!id is serial;
has Str $.name is column;
has @.books is relationship(*.author-id, :model<Book>, :prefetch);
}
for Person.^all.grep: *.books.elems > 0 -> $author {
say “{ $author.name }: { $author.books.join: “, “ }”
} Should it run: SELECT person.id, person.name, book.id as ‘book__id’, book.name as ‘book__name’, book.author_id as ‘book__author_id’ FROM person JOIN book ON person.id = book.author_id ORDER BY person.id And on Seq, loop generating and accumulating Book objects while Person.id is the same, and when it changes, create the Person obj using the accumulated objects? |
I'm working on it now, and for now I have this:
it's not grouping the prefetches inside the object and returning an object a single time yet. But I was thinking... we have 2 possibilities here, the first one is doing the query as it is above and then iterate over all results to to create each object with all preaches inside of it. I was thinking on iterating until we find a different object, but we have no control over ORDER BY, so it may be on the wrong order. Then I thought on a different possibility, the query, instead, could be something like this:
And it would be much easier to create each object and its prefetches. But much harder to only select the needed prefetch rows. Any idea/suggestion here? |
I just committed a new branch (to-many-prefetch) (#563) with a PoC for SQLite doing prefetch the 2nd way. I'm testing it with:
It's still in the beginning, but I seems very interesting... Opinions? |
Maybe that may be an option for for #25 |
Now we can set the prefetches on a ResultSeq using the prefetch method:
|
(not recursive, yet...) |
Pg:
still a bit hardcoded, but I'm going to merge it. |
No description provided.
The text was updated successfully, but these errors were encountered: