In console, I run the following and any? returns true: drivers = Driver.select("drivers.*, drivers.id").joins([:reports, :driving_habits]).where("extract(MONTH FROM reports.time) = ? AND extract(YEAR FROM reports.time) = ?", 3, 2013).uniq.order("drivers.id asc").page(2).per(1) drivers.any? => true This correctly evaluates to true because the relation contains one returned record. However, I run the same query within the Rails app itself, and any? must evaluate @drivers in the view to either false or nil, because the else is triggered instead when I click on second page in view. What''s even weirder is that when I call inspect on @drivers, then @drivers.any? is evaluated to true in the view when I click on the second page using kaminari: @drivers = Driver.select("drivers.*, #{sort_column}") .joins([:reports, :driving_habits]) .by_month(for_selected_month.to_i, for_selected_year.to_i) .order(sort_column + " " + sort_direction) .page(params[:page]).per(1) puts "The drivers #{@drivers.inspect}" What''s driving all this weird behavior? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 3 April 2013 20:58, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> In console, I run the following and any? returns true: > drivers = Driver.select("drivers.*, > drivers.id").joins([:reports, :driving_habits]).where("extract(MONTH > FROM reports.time) = ? AND extract(YEAR FROM reports.time) = ?", 3, > 2013).uniq.order("drivers.id asc").page(2).per(1) > drivers.any? > => true > > This correctly evaluates to true because the relation contains one > returned record. > > However, I run the same query within the Rails app itself, and any? > must evaluate @drivers in the view to either false or nil, because the > else is triggered instead when I click on second page in view. What''s > even weirder is that when I call inspect on @drivers, then > @drivers.any? is evaluated to true in the view when I click on the > second page using kaminari: > > @drivers = Driver.select("drivers.*, #{sort_column}") > .joins([:reports, :driving_habits]) > .by_month(for_selected_month.to_i, > for_selected_year.to_i) > .order(sort_column + " " + sort_direction) > .page(params[:page]).per(1) > > puts "The drivers #{@drivers.inspect}" > > > What''s driving all this weird behavior?Can you show us the code where you perform the test that is failing? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
DALVIR SINGH KHOSA
2013-Apr-03 21:16 UTC
Re: strange behavior with active relation any? method
hola por favor yo quiero baja rubyonrails-talk este ymail gracias On 03/04/2013, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 3 April 2013 20:58, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote: >> In console, I run the following and any? returns true: >> drivers = Driver.select("drivers.*, >> drivers.id").joins([:reports, :driving_habits]).where("extract(MONTH >> FROM reports.time) = ? AND extract(YEAR FROM reports.time) = ?", 3, >> 2013).uniq.order("drivers.id asc").page(2).per(1) >> drivers.any? >> => true >> >> This correctly evaluates to true because the relation contains one >> returned record. >> >> However, I run the same query within the Rails app itself, and any? >> must evaluate @drivers in the view to either false or nil, because the >> else is triggered instead when I click on second page in view. What''s >> even weirder is that when I call inspect on @drivers, then >> @drivers.any? is evaluated to true in the view when I click on the >> second page using kaminari: >> >> @drivers = Driver.select("drivers.*, #{sort_column}") >> .joins([:reports, :driving_habits]) >> .by_month(for_selected_month.to_i, >> for_selected_year.to_i) >> .order(sort_column + " " + sort_direction) >> .page(params[:page]).per(1) >> >> puts "The drivers #{@drivers.inspect}" >> >> >> What''s driving all this weird behavior? > > Can you show us the code where you perform the test that is failing? > > Colin > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.