0
의 합계를 얻기 : 청구서 및 지불액티브 나는이 개 모델이 모든 관련 기록
나는 송장의 관점에서 요약 할 필요가# == Schema Information
#
# Table name: invoices
#
# id :integer not null, primary key
# totale :decimal(8, 3)
# ....
# ....
#
class Invoice < ActiveRecord::Base
has_many :payments
end
# == Schema Information
#
# Table name: payments
#
# id :integer not null, primary key
# invoice_id :integer
# importo :decimal(8, 3)
# ....
#
class Payment < ActiveRecord::Base
belongs_to :invoice
end
을 각 송장 반복하지 않고 모든 지불의 importo의 합계.
어떻게 찾을 수 있습니까? 나는 시도했다
@fatture = Invoice.all
@fatture.payment.sum(:importo)
succes !!
좋아! 내 문제를 해결해 주셔서 감사합니다! – EffeBi