Assume 3 schemas:
C preloads a record of
The scenario above causes an infinite recursion (loop) when preloading recursively under the following condition:
How should I efficiently restrict the condition above from happening? Can someone please provide sample code to test the logic above?
@ion Preloading does not cause infinite recursion on its own, because when you call
preload you do so with a tree, and it only preloads to the depth of that tree. Can you show the code that you have which is recursing infinitely?
Per the code you DMed me, the reason it recurses infinitely is that you’re manually introducing infinite recursion.
You should consider doing something more like:
A |> preload([b: :c]) |> Repo.all.
Basically the issue is that SQL modeling like you have forms a cyclic graph, and you are looking to return a tree.