How do i preload this correctly?
This code is on my LV mount
to get a list of data
data =
Function.get(data1, data2, [
{:a, [:ab, :ac]},
# {:bc, [:bca, :bcab, {:bd, [:be]}]},
:c
])
The code above works fine, but if i remove the commented line
data =
Function.get(data1, data2, [
{:a, [:ab, :ac]},
{:bc, [:bca, :bcab, {:bd, [:be]}]},
:c
])
it will result to <association :bc is not loaded>
or :bc does not have association or embed :a
If i moved the preloaded schemas to this
data =
Function.get(data1, data2, [
:c,
{:a, [:ab, :ac]},
{:bc, [:bca, :bcab, {:bd, [:be]}]}
])
then the error would be :a does not have association or embed :c
can someone explain why i’m getting this error? and how it would be solved?
This is the get
Function i’m using.
def get(struct, id, preloaded) do
struct
|> preload(^preloaded)
|> Repo.get(id)
end
If i directly put the preloaded data here everything works fine, for example:
def get(struct, id, _preloaded) do
struct
|> preload([
:c,
{:a, [:ab, :ac]},
{:bc, [:bca, :bcab, {:bd, [:be]}]}
])
|> Repo.get(id)
end