Strange Array behaviour

invoice_lines.class returns Array, but invoice_lines is not an Array, but an association proxy.

This association proxy defines a sum (and count etc...) method that is analogous to the one available on any model.
So in the same way that you would do Invoice.sum(:column_name), you need to do invoice_lines.sum(:total)

The reason the to_a makes a difference is that it forces the proxy class to give you the real array.