Hmm... I would've thought that the join wouldn't imply a restriction
like the includes do but I've not run across your situation so I'm not
sure.  How many customers per page?  Can you get by with the N+1 db
calls from not including either?  If not, might be a case for a
find_by_sql call.

One thing, you don't need to use hobo_index necessarily.  You can get
similar results by doing your own pagination.

On Feb 4, 5:01 pm, Gabriele Tassoni <[email protected]>
wrote:
> From what I can see, chaining them is not like saying "either ...
> or ..." i.e. I have 2600 customers with cellphones, and 4 with emails,
> with 3 that have both, What I want is obtain 2601 records so far (it
> would be good even to have 2604, I can add a :group condition...), but
> what I obtain is 3 records, the customers that have both an email and
> a cellphone... so, chaining is like intersection, not concatenation...
>
> On 5 Feb, 00:50, kevinpfromnm <[email protected]> wrote:
>
> > You can't just chain your named_scopes?
> > Customer.with_cellphones.with_emails
>
> > On Feb 4, 4:11 pm, Gabriele Tassoni <[email protected]>
> > wrote:
>
> > > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to