1
有沒有什麼辦法強制will_paginate插件使用counter_cache而不是使用 SELECT count(*)
查詢?我聽說Model.count默認使用計數器緩存。所以will_paginate必須使用size方法。我如何改變它收集要分頁的對象數量的方式?計數器緩存和will_paginate
有沒有什麼辦法強制will_paginate插件使用counter_cache而不是使用 SELECT count(*)
查詢?我聽說Model.count默認使用計數器緩存。所以will_paginate必須使用size方法。我如何改變它收集要分頁的對象數量的方式?計數器緩存和will_paginate
假設兩種型號,Author
和Comment
,其中Author
has_many
Comment
S使用計數器緩存,你應該能夠選項:total_entries
傳遞給paginate
- 方法是這樣的:
author = Author.first
posts = author.posts.paginate :total_entries => author.posts_count
查看更多在這裏:https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/active_record.rb#L128