** (CompileError) nofile: invalid quoted expression: #Ecto.Query

74 views
Skip to first unread message

Vlad Alyukov

unread,
Sep 8, 2016, 8:24:53 AM9/8/16
to elixir-lang-talk

Hi there, 


When I try to make up a new hex (something like ransack in ruby land) I have the next problem:


===

  defp match(%Rule{op: :eq, field: field, assoc: nil}, value, query) do

    quote do: unquote(query) |> where([q], q.unquote(field) == ^unquote(var!(value)))

  end

  defp match(%Rule{op: :eq, field: field, assoc: assoc}, value, query) do

    quote do

      unquote(query)

      |> join(:inner, [r], l in assoc(r, unquote(var!(assoc))))

      |> where([q], q.unquote(field) == ^unquote(var!(value)))

    end

  end

===


first function works well, but when I try to pass "unquote(query)" (regular "Ecto.Query" struct) to macros "join", I got an exception like this:


===

    ** (CompileError) nofile: invalid quoted expression: #Ecto.Query<from o in Order>

===


Did I do something wrong? Why "where" and "join" macros have different semantics? And, of course is there other way to build dynamic queries?

OvermindDL1

unread,
Sep 8, 2016, 9:57:29 AM9/8/16
to elixir-lang-talk
It might be better to ask this on the https://elixirforum.com/ site.

Initially though, I'm curious what the quote'ing and such there is for, are these functions being used in a macro?  Ecto queries are very changeable without macro's too.

Vlad Alyukov

unread,
Sep 9, 2016, 9:20:48 AM9/9/16
to elixir-lang-talk
Thank you for your advise.
I made topic with verbose explanation of my problem and examples. 

But could you please explain what did you mean? I try to change query via public API, and all my attempts lead to nothing.  
I know that I can change Ecto.Query struct directly, but I would not like to stick to internal realization of Ecto.Query. I want implement this with public API. 

--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/_7Ua6-qt8uc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/aef453ae-ae54-4e66-9921-deeef3e7225f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages