0

Here area my relationships:

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

What I want to do is count how many recipients any given account has.

4

1 に答える 1

1

次のように、モデルに:through関係を追加する必要があります。Account

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

次に、これを行うことができます:

Account.first.recipients.count

それが役に立てば幸い

于 2012-08-29T16:19:37.610 に答える