【问题标题】:Ecto.Query.CompileError p.league().id() is not a valid query expressionEcto.Query.CompileError p.league().id() 不是有效的查询表达式
【发布时间】:2018-01-17 20:34:18
【问题描述】:

我正在尝试编写看似简单的 Ecto 查询,但我遇到了一个我不完全理解的错误。

基本上我正在尝试将两个 id 相互匹配。这是我目前的尝试:

查询

from(p in prediction_scores, where: p.league.id == ^league.id) 

错误

** (Ecto.Query.CompileError) `p.league().id()` is not a valid query expression
(ecto) expanding macro: Ecto.Query.where/3

我有一个属于LeaguePredictionScore,然后我有一个传入单独的league 的函数。我的查询正在尝试将 prediction_score 联赛 id 与传入的联赛 id 进行匹配。

希望这是足够的信息...如果您需要查看更多信息,请告诉我,我很乐意更新。

【问题讨论】:

    标签: elixir phoenix-framework ecto


    【解决方案1】:

    你需要明确地做连接:

    from p in prediction_scores,
      join: l in assoc(p, :league),
      where: l.id == ^league.id
    

    【讨论】:

      猜你喜欢
      • 2021-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多