diff --git a/lib/flop/adapter/ecto.ex b/lib/flop/adapter/ecto.ex index f5fec9bf..3fb78706 100644 --- a/lib/flop/adapter/ecto.ex +++ b/lib/flop/adapter/ecto.ex @@ -256,6 +256,11 @@ defmodule Flop.Adapter.Ecto do @impl Flop.Adapter def apply_order_by(query, directions, opts) do + if Ecto.Queryable.to_query(query).order_bys != [] do + Logger.warning("The query you passed to flop includes order_by.\ + This may interfere with Flop's ordering and pagination features.") + end + case opts[:for] do nil -> Query.order_by(query, ^directions) diff --git a/test/adapters/ecto/cases/flop_test.exs b/test/adapters/ecto/cases/flop_test.exs index 5a4be393..164cfda9 100644 --- a/test/adapters/ecto/cases/flop_test.exs +++ b/test/adapters/ecto/cases/flop_test.exs @@ -6,6 +6,7 @@ defmodule Flop.Adapters.Ecto.FlopTest do doctest Flop, import: true + import ExUnit.CaptureLog import Ecto.Query import Flop.Factory import Flop.Generators @@ -167,6 +168,15 @@ defmodule Flop.Adapters.Ecto.FlopTest do for: Owner ) == Enum.reverse(expected) end + + test "warns if query passed to Flop already included ordering" do + query = from p in Pet, order_by: :species + + assert capture_log(fn -> + Flop.all(query, %Flop{order_by: [:species, :name]}) + end) =~ + "This may interfere with Flop's ordering and pagination features" + end end describe "filtering" do