我有当前的find语句: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"
我只想提取那些contact_email,contact_letters等具有date_sent<的实例。 report_end_date和date_sent> report_start_date。
我该怎么做?
答案 0 :(得分:1)
添加conditions
。例如:
:conditions => ['contact_emails.date_sent < ? and contact_emails.date_sent > ?', report_end_date, report_start_date]