Search code examples
ormsql-updateelixirecto

Ecto update_all example


I would like to update all fields that match query

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

But I get:

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

What I do wrong here?


Solution

  • I'm not sure what your update function does but can you try passing in directly to Repo.update_all()

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