drewolson / scrivener

Pagination for the Elixir ecosystem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot use ^offset outside of match clauses

rafaeljesus opened this issue · comments

Hi,

I am getting the error below

=> scrivener
Compiled lib/scrivener/page.ex

== Compilation error on file lib/scrivener.ex ==
** (CompileError) lib/scrivener.ex:152: cannot use ^offset outside of match clauses
    (elixir) expanding macro: Kernel.|>/2
    lib/scrivener.ex:155: Scrivener.entries/4
    (elixir) expanding macro: Kernel.if/2
    lib/scrivener.ex:147: Scrivener.entries/4

Here is my module

defmodule EventTrack.Event do
  use Ecto.Schema
  import Ecto.Query
  import Ecto.Changeset
  alias EventTrack.{Repo, Event}

  def search(params \\ :empty) do
    page = Event
      |> where([e], e.name == ^params["name"])
      |> order_by([e], desc: e.inserted_at)
      |> Repo.paginate(params)
    // omited
  end

deps

 {:ecto, "~> 1.0.7", override: true},
 {:mongodb_ecto, "~> 0.1.4"},
 {:scrivener, "~> 1.0"}

Thx

@rafaeljesus Apologies, this was a regression against older versions of ecto (1.0.x). I've pushed a new version, 1.2.0, that should fix the problem.

No worries @drewolson

Upgrading to v-1.2.0 I get this

=> scrivener
Compiled lib/scrivener/config.ex

== Compilation error on file lib/scrivener.ex ==
** (Ecto.Query.CompileError) `count(field(m, ^primary_key), :distinct)` is not a valid query expression.

* If you intended to call a database function, please check the documentation
  for Ecto.Query to see the supported database expressions

* If you intended to call an Elixir function or introduce a value,
  you need to explicitly interpolate it with ^

    expanding macro: Ecto.Query.select/3
    lib/scrivener.ex:189: Scrivener.total_entries/2
    (elixir) expanding macro: Kernel.|>/2
    lib/scrivener.ex:190: Scrivener.total_entries/2

The code is here event_track

Unfortunately, although ecto 1.0.x supports count and field, there seems to be a bug around supporting dynamic fields inside of counts. I'm releasing 1.2.1 that only supports ecto ~>1.1. This should be a backwards compatible upgrade of ecto for you.

Ok @drewolson thank you for your quick replies