[英]Getting Record from Postgres using Ecto Elixir
我正在尝试通过 email 吸引用户。 获取合并 function 不存在,即使我没有编写合并 function。
代码
def get_user_by_email(email) do
User
|> preload(:exchange_accounts)
|> preload(:pos_account)
|> Repo.all(from u in User, where: u.email == ^email)
end
错误
iex(58)> AAK.POS.HelperFunction.get_user_by_email("sohaibanwaar36@gmail.com")
** (FunctionClauseError) no function clause matching in Keyword.merge/2
The following arguments were given to Keyword.merge/2:
# 1
[]
# 2
#Ecto.Query<from u0 in AAK.Accounts.User,
where: u0.email == ^"sohaibanwaar36@gmail.com">
Attempted function clauses (showing 3 out of 3):
def merge(keywords1, []) when is_list(keywords1)
def merge([], keywords2) when is_list(keywords2)
def merge(keywords1, keywords2) when is_list(keywords1) and is_list(keywords2)
(elixir 1.11.1) lib/keyword.ex:764: Keyword.merge/2
(aak 0.1.0) lib/aak/repo.ex:4: AAK.Repo.all/2
应该将Ecto.Query.preload/3
与查询一起使用,或者Ecto.Repo.preload/3
与结构一起使用,但不能混合使用。
下面是带有查询的变体。
def get_user_by_email(email) do
Repo.all(
from u in User,
where: u.email == ^email,
preload: ~w|exchange_accounts pos_account|a
)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.