LoginSignup
5
3

More than 5 years have passed since last update.

kaminariで君の街まで飛べればいいのにな。2017年梅雨

Posted at

kaminariと付き合い始めて約1年。
kaminariの知らない一面を見たのでご報告になります。

limitが無視される

User.count                     #=> 1000
a = User.limit(5); a.count     #=> 5
a.page(1).per(20).size         #=> 20

readmeには以下のように書いてあります。内部の処理でlimitを使っているので上書きしちゃうよ、とのこと。
Keep in mind that per internally utilizes limit and so it will override any limit that was set previously.

絞る前の個数を取得できる

User.count                     #=> 1000
User.page(1).per(20).size         #=> 20
User.page(1).per(20).total_count  #=> 1000

total_count知らなかったので、
わざわざuser_all_count = User.countみたいな変数用意してました。
必要なかったんですね。

以上、ご報告でした。

君の街まで飛ぶためのkaminariでした。:zap:

5
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3