Ecto get preloads

I’ve create a macro to automatic generate some preloads. Everything is working as expected, but I am not able to test it.

This is my test code:

    query = Lego.PreloadFactory.preload_for_bindings(query)
    preloads = IO.inspect(query)

The IO.inspect prints:

#Ecto.Query<from q0 in query, left_join: c1 in Lego.Course, as: :course,
 on: true, left_join: c2 in assoc(c1, :course_modules), as: :course_modules,
 left_join: m3 in assoc(c2, :module), as: :module,
 left_join: m4 in assoc(m3, :modules), as: :module_section,
 left_join: s5 in assoc(m4, :section), as: :section,
 preload: [course_modules: {c2, [module: {m3, [module_section: {m4, [section: s5]}]}]}]>

Where the line preload: [course_modules: {c2, [module: {m3, [module_section: {m4, [section: s5]}]}]}] is exactly what I need to assert, however I am not able to get the preloads. query.preloads returns an empty array. If the data that I want is been printed I image that is possible to get it somehow.

The field in the Ecto.Query struct is named preloads (plural) not preload (singular):

1 Like