associations - How can I count and filter on an associated record in Rails? -
company has_many contacts
company has_many contactemails :through => :contacts
contactemail belongs_to contact
contact belongs_to company
contact has_many contactemails
for specific instance of company, how can find contactemails , filter on attribute, such date_sent?
i tried company.contactemails don't think can make association.
you want use named scope this. works rails 2.3, wouldn't change rails 3.
i haven't tested it, should work. conditions may need tweaked proper date comparison.
contactemail < activerecord::base named_scope :by_date_sent, lambda {|d| { :conditions => ["date_sent = ?", d]}} end @company.contact_emails.by_date_sent(date.today)
Comments
Post a Comment