elixirdrops / kerosene

Pagination for Ecto and Pheonix.
https://github.com/elixirdrops/kerosene
MIT License
231 stars 39 forks source link

Fix total count query when group by clause is present #26

Closed feymartynov closed 7 years ago

feymartynov commented 7 years ago

For queries with group by clause total count query fails:

     ** (Ecto.MultipleResultsError) expected at most one result but got 10 in query:

     from p in Kerosene.Product,
       left_join: o in assoc(p, :orders),
       group_by: [p.id],
       select: count(p.id, :distinct)

This PR fixes it by wrapping such queries in a subquery.

allyraza commented 7 years ago

I am going to revert this, please make sure test pass

feymartynov commented 7 years ago

It passes screen shot 2017-05-21 at 15 20 58

allyraza commented 7 years ago

some weird is going on I ran the test and it fails

feymartynov commented 7 years ago

What Elixir version did you use?

Mine is:

Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.4.4

Btw, I think it would be nice if you enabled Travis CI for this repo to test it with different Elixir and Erlang/OTP versions.

feymartynov commented 7 years ago

Also you could forget to run MIX_ENV=test mix ecto.migrate. This commit contains a migration.