Search code examples
elixirecto

How to update column with the same name in both tables in join query in Ecto


So there is update_all method in Ecto and from what I know, we are allowed to pass a join query to its. But then I realized that I have column with the same name which caused ambiguity in what column should be updated.

Repo.update_all(
  from(d in "dogs",
    inner_join: b in "bones",
    on: b.dog_id == d.id,
    where: d.status != "new",
    where: b.status != "new",
    update: [set: [status: "excellent"]]
  ), []
)

This resulted in column status from table dogs being updated, how can I then update the one from bones table?


Solution

  • By its nature, update_all will update the table in the from clause. If you want to update more than one table, you'll need to use Ecto.Multi