ecto update_all示例

问题描述

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

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"}]))