elixir - a 3 level deep relationship in Ecto -- how to preload -


i have quite several level relationship of models in project. in controller have this:

var1 = repo.get!(model1, 123) |> repo.preload([child_items1:  :child_items2]) 

this works fine have go 1 level deeper.

namely each child_items2 many child_items3. now, how can preload child_items3 each child_items2?

i use scopes. example in model(1) have with_model2 function preloads model2. load 3 associations in row, i'd have like:

def with_model2(query \\ __module__)   query, preload: [model2: ^model2.with_model3] end 

for model(1). , idea, model2 have

def with_model3(query \\ __module__)   query, preload: :model3 end 

i never went 3 level deep, assume work.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -