diff --git a/lib/dataloader/ecto.ex b/lib/dataloader/ecto.ex index 0db0570..33406b6 100644 --- a/lib/dataloader/ecto.ex +++ b/lib/dataloader/ecto.ex @@ -695,7 +695,7 @@ if Code.ensure_loaded?(Ecto) do records = records |> Enum.map(&Map.put(&1, field, empty)) results = - if query.limit || query.offset || Enum.any?(query.order_bys) do + if query.limit || query.offset do records |> preload_lateral(field, query, source.repo, repo_opts) else diff --git a/test/dataloader/ecto_test.exs b/test/dataloader/ecto_test.exs index bf6065f..4625970 100644 --- a/test/dataloader/ecto_test.exs +++ b/test/dataloader/ecto_test.exs @@ -308,7 +308,7 @@ defmodule Dataloader.EctoTest do assert message =~ "Cardinality" end - describe "has_many through:" do + describe "many_to_many" do test "basic loading works", %{loader: loader} do user1 = %User{username: "Ben Wilson"} |> Repo.insert!() user2 = %User{username: "Bruce Williams"} |> Repo.insert!() diff --git a/test/support/post.ex b/test/support/post.ex index 033de5d..478288d 100644 --- a/test/support/post.ex +++ b/test/support/post.ex @@ -5,7 +5,7 @@ defmodule Dataloader.Post do belongs_to(:user, Dataloader.User) has_many(:likes, Dataloader.Like) has_many(:scores, Dataloader.Score) - has_many(:liking_users, through: [:likes, :user]) + many_to_many(:liking_users, Dataloader.User, join_through: Dataloader.Like) field(:title, :string) field(:status, :string)