Double square brackets around preload when inspecting

I wrote this query:

    from(
    d in Doctor,
    join: h in assoc(d, hospitals),
    preload: [hospitals: :rooms, hospitals: :patients]
  )

When I IO.inspect it gives me preload like this in the console:

                           preload: [hospitals: [:patients], hospitals: [:rooms]]

If I use List.flatten in preload, it gives me nested square brackets.

                          preload: [[hospitals: :patients, hospitals: :rooms]]

I want to return it like normal preload like this.

                      preload: [hospitals: :patients, hospitals: :rooms]

Why such behavior?
I am not running this query. I am just asserting it with the query my function is returning.
Any help will be much appreciated.
Thanks

[hospitals: [:patients], hospitals: [:rooms]] and [hospitals: :patients, hospitals: :rooms] does the same when in comes to what those would preload. Ecto probably normalizes the preload structure, so downstream code doesn’t need to handle each and every format allowed as input for preloads.

Ecto.Query for the most part is an opaque type, which might change its implementation at any time. The only good way to assert a query is correct is running it.

2 Likes