Skip to content

Javascript in "where" clause not behaving as expected in Phoenix #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lostboy opened this issue Jan 13, 2016 · 6 comments
Closed

Javascript in "where" clause not behaving as expected in Phoenix #60

lostboy opened this issue Jan 13, 2016 · 6 comments

Comments

@lostboy
Copy link

lostboy commented Jan 13, 2016

Hopefully this is just my own lack of understanding but i'm trying to use mongodb_ecto (0.1.2 or HEAD) in a Phoenix (1.1.2) app with Phoenix Ecto (2.0.0).

I'm trying to use javascript in the where clause as documented but it complains of

** (Ecto.QueryError) web/models/post.ex:15: value `%Mongo.Ecto.JavaScript{code: "this.value == count", scope: [count: 1]}` in `where` cannot be cast to type :boolean in query:

The model looks something like this

defmodule Project.Post do
  use Project.Web, :model

  import Ecto.Query, only: [from: 2]
  import Mongo.Ecto.Helpers

  alias Project.Repo

  schema "posts" do
    field :value, :integer
  end

  def test
    j = Mongo.Ecto.Helpers.javascript "this.value == count", count: 1
    q = from p in Project.Post, where: ^j
    Repo.all q
  end
end

The stacktrace seems to suggest that mongodb_ecto isn't even getting a look in so this quite possibly is a phoenix_ecto bug?

    (elixir) lib/enum.ex:1387: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir) lib/enum.ex:1102: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
      (ecto) lib/ecto/repo/queryable.ex:91: Ecto.Repo.Queryable.execute/5
      (ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
       (iex) lib/iex/evaluator.ex:117: IEx.Evaluator.handle_eval/5
       (iex) lib/iex/evaluator.ex:110: IEx.Evaluator.do_eval/3
       (iex) lib/iex/evaluator.ex:90: IEx.Evaluator.eval/3

Could you shed any light?

@lostboy lostboy changed the title Javascript in where not behaving as expected in Phoenix Javascript in "where" clause not behaving as expected in Phoenix Jan 13, 2016
@michalmuskala
Copy link
Collaborator

What's the ecto version?

@lostboy
Copy link
Author

lostboy commented Jan 15, 2016

Ecto is 1.1.1

@michalmuskala
Copy link
Collaborator

Ecto 1.1 unfortunately broke this feature. I'll be working today on fixing it.

@lostboy
Copy link
Author

lostboy commented Jan 21, 2016

Thanks @michalmuskala, I thought I was doing something wrong.

@michalmuskala
Copy link
Collaborator

Hey, I'm not sure if you were following other issues here, if not here's a quick rundown:

Unfortunately Ecto 1.1 broke some things for us and for the time being mongo_ecto is not compatible with Ecto 1.1. Even more unfortunately, right now, I have no time I could spare to fix those issues. Because of this, unless something changes, mongo_ecto will target the future release of Ecto 2.0 that should happen in about a month.

@ankhers
Copy link
Collaborator

ankhers commented Nov 27, 2017

I am going to close this. The JavaScript feature has been broken for a while and is being tracked in #106.

@ankhers ankhers closed this as completed Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants