2012-08-29 48 views
0

此处区域我的关系:通过另一个计算资源?

Account has_many :emails 
Email has_many :recipients 
Email belongs_to :account 
Recipient belongs_to :email 

我想要做的就是计算任何给定帐户多少收件人了。

回答

1

您需要在您的Account模型添加一个:through关系是这样的:

class Account 
    has_many :emails 
    has_many :recipients, :through => :emails 
end 

然后,你可以这样做:

Account.first.recipients.count 

希望它可以帮助

相关问题