Hi,
I try to explain better, I wrote a named scope like that:
named_scope :with_cellphones_or_emails, {:include =>
[:cellphones, :emails], :conditions => ["(cellphones.active = ? AND
cellphones.customer_id = customers.id) OR (emails.active = ? AND
emails.customer_id = customers.id)", true, true]}
for the Customer model, calling Customer.with_cellphones_or_emails
takes about 6 seconds on my macbook unibody with 2GB Ram, I’ve made
some tests, I wrote two more named_scopes:
named_scope :with_emails, {:joins => :emails, :conditions =>
{“emails.active” => true}}
named_scope :with_cellphones, {:joins => :cellphones, :conditions =>
{“cellphones.active” => true}}
running Customer.with_cellphones takes approx. 50ms,
Customer.with_emails takes approx 5ms (yeah, my customers have more
cellphones than emails! ^_^)… 55ms vs 6s! °_° (these are mysql
calculated times)…
Trying to minimize the time spent on db query, by single query, I
thought it could be great if I can concatenate the two results, indeed
I can do:
Customer.with_cellphones + Customer.with_emails
but the resulting object is an Array, is there a way to obtain an
ActiveRecord::NamedScope::Scope object?
Thank you for the answer.
G.