by kiru (11.11.2021)

Ecto 3 breaks assoc loaded

tl;dr

After migrating to Ecto 3, the following code did not work:

Ecto.assoc_loaded?(“e9d7edb4-3aef-45d6-851c-e77a464ef352”)

The Ecto.assoc_loaded?() does not accept any objects, check manually before you call assoc_loaded?()

Looking at the source code:

In Ecto 2.2:

  def assoc_loaded?(association) do
    case association do
      %Ecto.Association.NotLoaded{} -> false
      _ -> true
    end
  end

In Ecto 3:

  def assoc_loaded?(%Ecto.Association.NotLoaded{}), do: false
  def assoc_loaded?(list) when is_list(list), do: true
  def assoc_loaded?(%_{}), do: true
  def assoc_loaded?(nil), do: true