will_paginate reporting too many entries and pages

前端 未结 2 795
死守一世寂寞
死守一世寂寞 2021-01-05 14:59

I\'m using will_paginate to display data returned from a query that includes both a joins and a select statement. When I paginate the data the number of entries is equal to

相关标签:
2条回答
  • 2021-01-05 15:25

    It's always going to be slightly harder to paginate and join in has_many or has_and_belongs_to_many associations with will_paginate, or indeed any pagination solution.

    If you don't need to query on the joined in association you can remove it. You lose the benefit of getting the associated line items in one query but you don't lose that much.

    If you need to query on it, and presumably you want sales that only have line items, you'll need to pass in a :count option to the paginate call which specifies additional options that are used for the call to count how many items there are. In your case:

    @sales.paginate(:per_page => 4, 
        :page => params[page], 
        :count => {:group => 'sales.id' })
    
    0 讨论(0)
  • 2021-01-05 15:44

    Assuming that your Sale model has_many :line_items, by joining you're going to get a 'sales' entry for every related 'line_item'.

    0 讨论(0)
提交回复
热议问题