From 37cd17f761127b83c7c58e1a5848cdae7646514b Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 14 Aug 2023 12:51:54 -0400 Subject: [PATCH 1/3] don't lateral join just because we have order_bys --- lib/dataloader/ecto.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From cbb38a52ffd70e0f0f8630f2793e4e32af96c36e Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Thu, 16 May 2024 07:09:40 -0400 Subject: [PATCH 2/3] change to many to many to support test case --- test/support/post.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From f0b372b475d0e51fff9341f8660893b1fef1590d Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Thu, 16 May 2024 07:09:59 -0400 Subject: [PATCH 3/3] Improve test description --- test/dataloader/ecto_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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!()