Eagerly fetch nested relations? #649
Replies: 7 comments 3 replies
-
|
Hey @OskarPersson, two levels eager loading is not supported at the moment.
I guess it would be |
Beta Was this translation helpful? Give feedback.
-
|
hmm okay. How do you mean with "way too complex"? I feel like this is a pretty standard setup/problem and is supported in, for example, Django with
|
Beta Was this translation helpful? Give feedback.
-
|
Some kind of recursive call with a base case that falls back to lazy loading/fetching reference for cyclic relations might be one way to go about it. But I can see how it can quickly escalate in complexity. OTOH, running a subquery can be a workaround but that makes the application code messy quickly too. |
Beta Was this translation helpful? Give feedback.
-
At this early stage of sea-orm, we want to keep things simple, so we only allow fetching nested relation of one level deep, i.e. |
Beta Was this translation helpful? Give feedback.
-
|
+1 for me It's very common to have tables that exist primarily of a set of IDs referencing other tables, and you want to rebuild a view of the original data. E.g., a tables such as: events
purchasers
items
If you were selecting by Other ORMs I've worked with implement methods (in this example) on the Event model that allow fetching the related records (potentially referencing cached values). E.g., while there would be an |
Beta Was this translation helpful? Give feedback.
-
|
Hey @shutton, thanks for the proposal! Related discussion: |
Beta Was this translation helpful? Give feedback.
-
|
I think the problem mentioned by @shutton (A->B+C) is different from OP's problem (A->B->C) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When fetching a list of my table
FooI know that I can usefind_with_relatedto eagerly fetch each Foo objects relatedBar, giving me the following in return:Vec<(Foo, Vec<Bar>)>. This is perfect for when there is only one level of relation. But what if I also have a one-to-one relation fromBarnamedQux.What should I use if I want all three from the same query, i.e.
Vec<(Foo, Vec<(Bar, Qux)>)>?Beta Was this translation helpful? Give feedback.
All reactions