Was working in Phoenix 1.4.x , now fails to compile with Phoenix 1.5.1 [Ecto.Repo]

This was working in Phoenix 1.4.x , now fails with error:

  def adjust_stock(move_list, source, ref) do
    move_list
    |> Stream.map(fn move ->
      StockWeb.Helpers.atomize(move)
    end)
    |> Stream.map(fn move ->
      current = # this line fails to compile
        Stock.Repo.one(
          Stock.Moves.Move
          |> join(:left, [m], item in Stock.Items.Item, m.item_id == item.id)
          |> where([m, item], item.effective_item_id == ^move.item_id)
          |> where([m, item], m.stock_count == 1)
          |> where([m, item], m.flag == 1)
          |> where([m, item], item.status == 1)
          |> select([m, item], sum(m.quantity))
        )

Error:

== Compilation error in file lib/stock/moves/moves.ex ==
** (FunctionClauseError) no function clause matching in Ecto.Query.join/5
    expanding macro: Ecto.Query.join/5
    lib/stock/moves/moves.ex:116: Stock.Moves.adjust_stock/3

You need to put the on: before m.item_id == item.id, see the reference

6 Likes

Exaclty, that’s one of the biggest changes from Ecto 2.x to 3.x in terms of breaking-syntax.

2 Likes