Ecto not returning the expected results from query

I translate your SQL as:

from(p in Epr.Payments.PaymentOrder, [
  left_join: i in Epr.Debts.Invoice, on: p.id == i.payment_order_id,
  group_by: p.id,
  select: %{
    id: p.id,
    void: p.void,
    num: p.num,
    invoice_amount: sum(i.amount)
  }
])

you are using a where instead of fully specifying the left join - this means you actually have an inner join rather than a left join.

Also running the query in iEX would show you the SQL that Ecto generates (example).

3 Likes