Well, it kind of does the wrong join:
>> c = Customer.all.reject{|j| j.jobs.empty?}
[...]
>> c.size
=> 2125
>> c = Customer.with_jobs
Customer Load (165.5ms) SELECT SQL_NO_CACHE `customers`.* FROM `customers` INNER JOIN `jobs` ON jobs.customer_id =
customers.id WHERE (jobs.customer_id IS NOT NULL)
...
>> c.size
15692
What it ends up giving me is one customer record for every job that *had* a customer, which means I actually get duplicate customer records. If a customer has 3 jobs, then he's in that result set 3 times.
What I'm after is a result set of all the customers that had a job, but no duplicates.
But while writing this it occurred to me: add a :group to your suggestion. So I tried this, and it works:
named_scope :with_jobs, :joins => [:jobs], :conditions => "jobs.customer_id IS NOT NULL", :group => "
customers.id"
With the :group added, it worked, so you rock! Thanks so much for the help!