i got unsupported :as in keyword query expression
when trying to do named join
query = AccountAuth
# Filter by the join
query = from a in query,
join: i in AccountInfo, as: :info, where: a.phone_number == i.wid
# Extend the query
query = from [a, info: i] in query,
select: {a.id, a.phone_number, i.device_manufacturer}
query =
query
|> Repo.all()
working version is
# Create a query
query = from(a in AccountAuth, join: i in AccountInfo, where: a.phone_number == i.wid)
Extend the query
query =
from([a, i] in query,
select:
{a.id, a.phone_number, i.device_manufacturer}
)
but the result is {xx, xxx, “xxx”} ( i dont get the array of struct ( with key), because i want to convert that to json )
the second version is https://github.com/elixir-ecto/ecto/issues/2389#issue-290497299
2 Likes
Eiji
March 24, 2019, 4:30pm
3
Do you have latest ecto
and ecto_sql
? Maybe you are using version before introducing this feature … If I remember correctly it was added in 3.0.0
version.
1 Like
defp deps do
[
{:phoenix, "~> 1.3.4"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.2"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.10"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:plug_cowboy, "~> 1.0"},
{:bcrypt_elixir, "~> 2.0"}
]
end
{:phoenix_ecto, "~> 3.2"}
i’m i wrong ?
Eiji
March 24, 2019, 5:23pm
5
jihantoro:
i’m i wrong ?
end
defp package do
[maintainers: ["José Valim", "Chris Mccord"],
licenses: ["Apache 2.0"],
links: %{"GitHub" => "https://github.com/phoenixframework/phoenix_ecto"}]
end
defp deps do
[{:phoenix_html, "~> 2.9", optional: true},
{:ecto, "~> 2.1"},
{:plug, "~> 1.0"}]
end
end
Yup, looks like so …
Following:
you need to require 4.0.0
or higher version.
2 Likes
yeah, i’ll update it, and just i write another alternative <3,
query = from(a in AccountAuth, where: a.username == ^username) |> Repo.all()
data = Enum.map(
query,
fn elem ->
device = from(i in AccountInfo, where: i.wid == ^elem.phone_number) |> Repo.one()
if device != nil do
%LoggedAccount{
id: elem.id,
phone_number: elem.phone_number,
device: device.device_manufacturer
}
end
end
)