If I have these classes:
class Customer < ActiveRecord::Base
has_many :jobs
...
end
class Job < ActiveRecord::Base
belongs_to :customer
...
end
can I construct a named scope that returns the equivalent collection (but
hopefully more efficient) to this:
customers_with_jobs = Customer.all.reject{|t| t.jobs.empty?}
I don't care about the number of jobs a customer has, or the state any of
those jobs are in; I just want a named scope that will give me the ones who
have jobs associated with them, hopefully without the massive N+1 query
problem that the reject{...} gets me.
It seems like this should be a relatively simple thing, but it has eluded me
so far.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.