这是我的关系区域:
Account has_many :emails
Email has_many :recipients
Email belongs_to :account
Recipient belongs_to :email
我想要做的是计算任何给定帐户的收件人数。
答案 0 :(得分:1)
您需要在:through
模型中添加Account
关系,如下所示:
class Account
has_many :emails
has_many :recipients, :through => :emails
end
然后你可以这样做:
Account.first.recipients.count
希望有所帮助