gpt4 book ai didi

mysql - 在 Rails 中组合多个模型

转载 作者:行者123 更新时间:2023-11-29 23:46:27 25 4
gpt4 key购买 nike

class BankTeller < ActiveRecord::Base
belongs_to :finance_transaction
belongs_to :institution_bank_account
end

class InstitutionBankAccount < ActiveRecord::Base
has_many :bank_tellers
end

class FinanceTransaction < ActiveRecord::Base
has_one :bank_teller
end

金融交易有一个金额字段。如何获取按机构银行帐户分组的所有金融交易中的金额总和?

编辑:我的应用程序使用 Rails 版本 2.3.8。

最佳答案

我用过:

BankTeller.all(:joins => [:finance_transaction, :institution_bank_account], :group => "institution_bank_accounts.id", :select=> ('institution_bank_accounts.id, sum(amount)'))

关于mysql - 在 Rails 中组合多个模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25910170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com