I am using select merge to build the query dynamically. But i can’t understand why ecto give me these errors.
this is the query
Ecto.Query<from r0 in Room,
select: merge(f0, %{"$aggregate": %{"$count": %{^"floor" => count(f0.floor)}}})>
this is the code:
from(
r in rooms,
select_merge: %{"$aggregate": %{"$count": %{^field => count(field(r, ^atom_field))}}}
)
and I got this error:
struct Room `does not have the key :"$aggregate".
And if i use it in joins:
this is the query:
from(
h in Hospital,
right_join: r in "rooms",
on: h.id == r.hospital_id,
where: r.name == ^"room 1" and ^true,
select: merge(h, %{^:rooms => map(r, [:name, :purpose, :description])})
)
this is the code:
from(
[h, ..., r] in hospital,
select_merge: %{
^String_to_atom(rooms) => map(r, [:fields])
}
)
the error is:
Postgrex expected a binary, got :rooms. Please make sure the value you are passing matches the
definition in your table or in your query or convert the value accordingly.
If i change the rooms to string it will throw the same error i am getting in the count query.
May be I am missing something very obvious here.
Any help will be much appreciated
Thanks