Here's the situation...
:customer has_many :billing_windows
:billing_window belongs_to :customer
A billing_window can either be open or closed (it is considered open
until its closed_on attribute is set to a datetime). I'm trying to
refactor the class method on Customer that finds all customers with at
least 1 open billing_window. Currently it looks like this...
set = 
Customer.find(:all).each do |customer|
set << customer if customer.billing_windows.find(:all, :conditions
=> [:open => true]).size > 0
For obvious reasons, this is horribly inefficient so I have refactored
that code to:
Customer.find(:all, :joins => :billing_windows, :conditions =>
"billing_windows.closed_on IS NULL")
This definitely seems cleaner but I don't like the fact that the
conditions clause is specific to the database query language. Does
anyone know a better way to accomplish this?