ecto如何仅在更新时修改update_at

时间:2017-03-31 06:22:20

标签: elixir ecto

当插入具有唯一索引的数据时,我只想更新updated_at值,而不是id + 1如何做到这一点?

Repo.insert_all(Ecto.module, all, on_conflict: :replace_all)

on_conflict:设置
我不知道如何获得当前时间, Ecto.DateTime.utc是错误

如何撰写Repo.insert_all

模式(模型)

defmodule Zerg.VContractVContractGroup do
  use Zerg.Web, :model

  schema "vcontracts_vcontract_groups" do
    belongs_to :vcontract, Zerg.VContract
    belongs_to :vcontract_group, Zerg.VContractGroup

    timestamps()
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:vcontract_id, :vcontract_group_id])
    |> validate_required([:vcontract_id, :vcontract_group_id])
  end
end

0 个答案:

没有答案