[#<ActiveRecord::Associations::CollectionProxy [#<InvoiceServiceType id: 1, value_charged: 50.0, invoice_id: 4, service_type_id: 1>, #<InvoiceServiceType id: 2, value_charged: 50.4, invoice_id: 4, service_type_id: 2>]>, #<ActiveRecord::Associations::CollectionProxy [#<InvoiceServiceType id: 8, value_charged: 70.0, invoice_id: 1, service_type_id: 2>, #<InvoiceServiceType id: 9, value_charged: 50.0, invoice_id: 1, service_type_id: 6>]>]
我想将所有value_charged加起来。
我试试map(&amp;:value_charged).sum 搜集.. 什么都没有:(
谢谢
答案 0 :(得分:1)
假设您有@object
has_many
关系details
,details
有字段调用:value_charged
,您可以尝试将所有:value_charged
的{{1}}:
@object.details