Kaminary breaks scopes with multiple "where" calls #166

Closed
cryo28 opened this Issue Oct 1, 2011 · 5 comments

Comments

Projects
None yet
4 participants

cryo28 commented Oct 1, 2011

Given ActiveRecord::Relation

Request.where(:id => 1).where(:id => 2)
SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 AND "requests"."id" = 2

Correct query:

Request.page(1).where(:id => 1).where(:id => 2)
SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 AND "requests"."id" = 2 LIMIT 25 OFFSET 0

Incorrect query:

Request.where(:id => 1).where(:id => 2).page(1)
SELECT "requests".* FROM "requests" WHERE "requests"."id" = 2 LIMIT 25 OFFSET 0
Owner

amatsuda commented Oct 1, 2011

I'm sorry, I couldn't reproduce this behavior.
Could you show me your Gemfile?

the8472 commented Jul 2, 2012

I'm having a similar issue. And it only seems to happen on the second query issued to the model, the first paginated query is calculated correctly. So i'm suspecting some caching issues here.

Trying to narrow it down atm.

the8472 commented Jul 2, 2012

It seems to be happening somewhere in the page scope but i have no clue why.

doesn't work:

  relation = relation.page(@page_var)
  relation = relation.per(@count) if count

works even though it should be doing the same as the code above:

  class << relation
    include Kaminari::ActiveRecordRelationMethods
    include Kaminari::PageScopeMethods
  end

  relation = relation.limit(default_per_page).offset(default_per_page * ([@page_var.to_i, 1].max - 1))
  relation = relation.per(@count) if @count

Using kaminari 0.13.0, rails 3.2.6 and squeel 1.0.6

the8472 commented Jul 2, 2012

I think this is caused by rails/rails#3052

Owner

yuki24 commented Jun 18, 2013

I'm closing this isssue. The reason why I close this issue is that #307 contains more comments than this issue. Please see #307 for more detials. Thanks!

yuki24 closed this Jun 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment