When doing the query operation, the total_count obtained is not the expected result.

this query operation I used the query plug-in ( rummage_ecto ),
is the command line test:

iex(4)rummage = %{
...(4)>       search: %{name:  %{search_type: :like, search_term: "c"}},
...(4)>       sort: %{field: :name, order: :asc},
...(4)>       paginate: %{page: 1}
...(4)>     }
%{paginate: %{page: 1},
search: %{name: %{search_term: "c", search_type: :like}},
sort: %{field: :name, order: :asc}}

iex(5)> {queryable, rummage} = ZergApi.Base.Exchange.rummage(rummage)
[debug] QUERY OK source="exchanges" db=0.1ms
SELECT count(DISTINCT e0.`id`) FROM `exchanges` AS e0 []
{-sharpEcto.Query<from e in subquery(from e in subquery(from e in ZergApi.Base.Exchange),
where: like(e.name, ^"%c%")),
order_by: [asc: e.name], limit: ^10, offset: ^0>,
%{paginate: %{max_page: 1, page: 1, per_page: 10, total_count: 10},
 search: %{name: %{assoc: [], search_expr: :where, search_term: "c",
     search_type: :like}},
 sort: %{assoc: [], field: :name, order: :asc}}}

there are ten pieces of data in this table. After the search operation, three pieces of data will be returned, that is, total_count = 3, but ten pieces of data will actually be returned, that is, total_count = 10, and the following is the actual data.

the following is the actual data returned

iex(6)> exchanges = queryable |> ZergApi.Repo.all
[debug] QUERY OK db=0.4ms
SELECT s0.`id`, s0.`name`, s0.`cn_name`, s0.`home_page`, s0.`timezone`, s0.`inserted_at`, s0.`updated_at` FROM (SELECT s0.`id` AS `id`, s0.`name` AS `name`, s0.`cn_name` AS `cn_name`, s0.`home_page` AS `home_page`, s0.`timezone` AS `timezone`, s0.`inserted_at` AS `inserted_at`, s0.`updated_at` AS `updated_at` FROM (SELECT e0.`id` AS `id`, e0.`name` AS `name`, e0.`cn_name` AS `cn_name`, e0.`home_page` AS `home_page`, e0.`timezone` AS `timezone`, e0.`inserted_at` AS `inserted_at`, e0.`updated_at` AS `updated_at` FROM `exchanges` AS e0) AS s0 WHERE (s0.`name` LIKE ?)) AS s0 ORDER BY s0.`name` LIMIT ? OFFSET ? ["%c%", 10, 0]
[%ZergApi.Base.Exchange{__meta__: -sharpEcto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 5,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: -sharpEcto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]},
 %ZergApi.Base.Exchange{__meta__: -sharpEcto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 6,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: -sharpEcto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]},
 %ZergApi.Base.Exchange{__meta__: -sharpEcto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 4,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: -sharpEcto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]}]

can you give me some suggestions?

Mar.04,2021
Menu