defmodule Arcade.TemplateMedia do
use Ecto.Schema
import Ecto.{Changeset, Query}
def for_template_id(query \ MODULE, t_id) do
from u in query,
where u.template_id == ^t_id
end
== Compilation error in file lib/arcade/template_media.ex ==
** (ArgumentError) second argument to from must be a compile time keyword list
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用这个函数传递到Repo.all()
我不明白这个错误。我在另一个项目中有相同类型的代码,没有问题。这是版本之间的 Ecto 语法问题吗?对我来说这看起来很简单。我缺少什么?
在您编写的代码中,第二个参数from是这部分:where u.template_id == ^t_id。ArgumentError 试图告诉您将其转换为关键字列表。你可以像这样详细地写它,[{:where, u.template == ^t_id}]但大多数人会这样写:
def for _template_id(query \\ __MODULE__, t_id) do
from u in query,
where: u.template_id == ^t_id
end
Run Code Online (Sandbox Code Playgroud)
这就是说你忘记了后面的冒号where。