protocol Scrivener.Paginater not implemented for #Ecto.Query
jaimeiniesta opened this issue · comments
Hello, I had pagination working fine in my app using:
- phoenix 1.1.4
- phoenix_ecto 2.0
- scrivener_html 1.1
- scrivener 1.1.4
But now, after upgrading to:
- phoenix 1.2.0
- phoenix_ecto 3.0
- scrivener_html 1.3
- scrivener 2.0.0
It's failing with:
[error] #PID<0.4760.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /s
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Scrivener.Paginater not implemented for #Ecto.Query<from s in MyApp.Sitemap, where: s.user_id == ^1, order_by: [desc: s.inserted_at]>
lib/scrivener/paginater.ex:1: Scrivener.Paginater.impl_for!/1
lib/scrivener/paginater.ex:10: Scrivener.Paginater.paginate/2
(MyApp) web/controllers/sitemap_controller.ex:28: MyApp.SitemapController.index/2
(MyApp) web/controllers/sitemap_controller.ex:1: MyApp.SitemapController.action/2
(MyApp) web/controllers/sitemap_controller.ex:1: MyApp.SitemapController.phoenix_controller_pipeline/2
(MyApp) lib/MyApp/endpoint.ex:1: MyApp.Endpoint.instrument/4
(MyApp) lib/phoenix/router.ex:261: MyApp.Router.dispatch/2
(MyApp) web/router.ex:1: MyApp.Router.do_call/2
(MyApp) lib/MyApp/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
(MyApp) lib/plug/debugger.ex:93: MyApp.Endpoint."call (overridable 3)"/2
(MyApp) lib/MyApp/endpoint.ex:1: MyApp.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
I've already cleaned up and reinstalled the deps, not sure what is failing here. This is the code in the controller:
def index(conn, params) do
sitemaps = Sitemap
|> where(user_id: ^(current_user(conn).id))
|> order_by(desc: :inserted_at)
|> Repo.paginate(params)
render(conn, "index.html", sitemaps: sitemaps)
end
Any idea?
Thanks!
(Comes from mgwidmann/scrivener_html#30)
@jaimeiniesta Hi! With the upgrade of scrivener to 2.0
, the ecto-specific functionality has moved to scrivener_ecto (see the note at the top of the README). Including that library should fix your issue (assuming scrivener_html
works with scrivener 2.0
).
That was it! It works fine now, thanks a lot.
It appears when using the new MyXQL driver, with the exact same error, just followed by
"...for type Ecto.Query (struct)
I had to switch back to mariaex to make it work again.
how to solve this error?