Hi there,
I tried to make ransack analogue and faced with the next problem: all Ecto.Query
macros like where
, order_by
, select
, etc. need to pass binding variables as second arguments for build queries with schema relations.
In my case I just try to translate map structure like this:
%{post_body_cont: "body", author_name_eq: "author"}
to Ecto.Query
like this:
Comment
|> join(:inner, [c], p in assoc(c, :post))
|> join(:inner, [c], a in assoc(a, :author))
|> where([c, p, a], like(field(p, :body), "%body%"))
|> where([c, p, a], field(p, :body) == "author")
The problem is that I donāt know how many relation can be represented in the map. There is some approach to build and pass that bindings dynamically?