0
此处区域我的关系:通过另一个计算资源?
Account has_many :emails
Email has_many :recipients
Email belongs_to :account
Recipient belongs_to :email
我想要做的就是计算任何给定帐户多少收件人了。
此处区域我的关系:通过另一个计算资源?
Account has_many :emails
Email has_many :recipients
Email belongs_to :account
Recipient belongs_to :email
我想要做的就是计算任何给定帐户多少收件人了。
您需要在您的Account
模型添加一个:through
关系是这样的:
class Account
has_many :emails
has_many :recipients, :through => :emails
end
然后,你可以这样做:
Account.first.recipients.count
希望它可以帮助