Elixir 对多字段使用验证

Elixir 对多字段使用验证,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,我尝试添加验证,如validate_change,但包含两个字段:from_id,:to_id。我想测试此元组是否在管理表中,或者不应插入: def changeset_create(%Task{} = task, attrs) do task |> cast(attrs, [:title, :body, :finished, :from_id, :to_id]) |> validate_required([:title, :body, :finished

我尝试添加验证,如validate_change,但包含两个字段:from_id,:to_id。我想测试此元组是否在管理表中,或者不应插入:

  def changeset_create(%Task{} = task, attrs) do
    task
    |> cast(attrs, [:title, :body, :finished, :from_id, :to_id])
    |> validate_required([:title, :body, :finished, :from_id, :to_id])
    |> foreign_key_constraint(:from_id)
    |> foreign_key_constraint(:to_id)
    |> validate_in_management()
  end

  def validate_in_management(changeset, _opts \\ []) do
    changeset
    |> validate_change(:from_id
  end

但是我不知道下一步怎么做,非常感谢。

我解决了我的问题,没有使用
validate\u change
,而是在管理中使用
validate\u(变更集,\\\[])

changeset
  |> add_error(:from_id, "not find from and to in management table.")
获取正确的变更集