Ecto update_all 示例

Ecto update_all example

我想更新所有匹配查询的字段

MyModel  
|> where([m], m.state == "begin") 
|> update([set: %{state: "commit"}]) 
|> Repo.update_all()

但我得到:

 malformed update `[set: %{state: "commit"}]` in query expression, expected a keyword list with set/push/pop as keys with field-value pairs as values

我这里做错了什么?

我不确定你的 update 函数是做什么的,但你可以尝试直接传递给 Repo.update_all()

Repo.update_all(from(m in MyModel, where: m.state == "begin", update: [set: [%{state: "commit"}]))