I have this code
defmodule Project.Search do
use Ecto.Model
defp search(query, search, order?) do
name_search = like_escape(search, ~r"(%|_)")
if String.length(search) >= 3 do
name_search = "%" <> name_search <> "%"
end
desc_search = String.replace(search, ~r"\s+", " & ")
query =
from var in query,
where: ilike(var.name, ^name_search) or
fragment("to_tsvector('english', (?->'description')::text) @@ to_tsquery('english', ?)",
var.meta, ^desc_search)
if order? do
query = from(var in query, order_by: ilike(var.name, ^name_search))
end
query
end
end
When I try to compile I got this error
== Compilation error on file web/models/search.ex ==
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:112: Enumerable.reduce/3
(elixir) lib/enum.ex:1274: Enum.reduce/3
expanding macro: Ecto.Model.Dependent.__before_compile__/1
web/models/search.ex:1: Project.Search (module)
This only happen with the last version of Phoenix, It was working with version 0.13.0
I have tried to change to use Project.Web, :model
but I got the same error.
use Ecto.Model
toimport Ecto.Query, only: [from: 2]
and seen that is working – Gidrek