views:

22

answers:

1

I have the current find statement with :select:

@list = Contact.find :all,
  :select => "companies.name AS co_name,  
              COUNT(contact_emails.id) AS email_count, 
              COUNT(contact_calls.id) AS call_count, 
              COUNT(contact_letters.id) AS letter_count, 
              COUNT(contact_postalcards.id) AS postalcard_count,",
  :joins => [
    "LEFT JOIN companies ON companies.id = contacts.company_id",
    "LEFT JOIN contact_emails ON contact_emails.contact_id = contacts.id",
    "LEFT JOIN contact_letters ON contact_letters.contact_id = contacts.id",
    "LEFT JOIN contact_postalcards ON contact_postalcards.contact_id = contacts.id",
    "LEFT JOIN contact_calls ON contact_calls.contact_id = contacts.id"
  ],
  #:group => "companies.id"
   :group => "companies.name"

I only want to pull up those instances where contact_email, contact_letters, etcetera have date_sent < report_end_date and date_sent > report_start_date.

How do I do that?

+1  A: 

By adding conditions. For example:

:conditions => ['contact_emails.date_sent < ? and contact_emails.date_sent > ?', report_end_date, report_start_date]
captaintokyo