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 it:
@customers = Customer.with_cellphones + Customer.with_emails
but the resulting object is an Array, the index action of the
controller is like this one:
hobo_index @customers, :order => :name, :group => "customers.id"
is there a way to obtain an ActiveRecord::NamedScope::Scope object
from that concatenation or to let hobo_index accept the Array?
Thank you for the answer.
G.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---