Module: ArOoSelect::WillPaginateExt
- Defined in:
- lib/mcmire/ar_oo_select/will_paginate_ext.rb
Instance Method Summary collapse
-
#oo_select_paginate(sql, options) ⇒ Object
Patch to use our oo_select_all instead of connection.select_all.
Instance Method Details
#oo_select_paginate(sql, options) ⇒ Object
Patch to use our oo_select_all instead of connection.select_all
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mcmire/ar_oo_select/will_paginate_ext.rb', line 4 def oo_select_paginate(sql, ) WillPaginate::Collection.create(*()) do |pager| query = sanitize_sql(sql) original_query = query.dup # add limit, offset add_limit! query, :offset => pager.offset, :limit => pager.per_page # perform the find pager.replace oo_select_all(query) unless pager.total_entries count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, '' count_query = "SELECT COUNT(*) FROM (#{count_query})" unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase) count_query << ' AS count_table' end # perform the count query pager.total_entries = count_by_sql(count_query) end end end |