How to provide a default value for Aggregates

  calculations do
    calculate :subtotal,
              :decimal,
              expr(
                type(price, :decimal) * type(quantity, :decimal) + type(modifiers_total, :decimal)
              )
  end

  aggregates do
    sum :modifiers_total, :modifiers, :total, public?: true
  end

If a particular record doesn’t have modifiers then subtotal ends up being nil, how do I default the result of the aggregate to "0" instead of nil?

I believe you can set default: 0 (on the aggregate).

1 Like

It’s so intuitive I missed it :man_facepalming:

1 Like