How do I do a .count on the model an object belongs_to in rails?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-12T00:05:25Z Indexed on 2010/05/12 0:14 UTC
Read the original article Hit count: 138

Filed under:
|

I have @contacts_added defined as follows:

@contacts_added = Contact.all(:conditions => ["date_entered >?", 5.days.ago.to_date])

Each contact belongs_to a Company.

I want to be able the count the number of distinct Companies that @contacts_added belong to. contacts_added will have many contacts that belong to a single company, accessible through a virtual attribute contacts_added.company_name

How do I do that?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about count