Skip to content

Commit

Permalink
[DEPRECATION] change count(distinct: true) to distinct.count
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaai committed Mar 27, 2014
1 parent 2bc1807 commit ce8c7eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/contract.rb
Expand Up @@ -139,7 +139,7 @@ def self.filter(params, user = nil, inventory_pool = nil)
contracts = contracts.where(Contract.arel_table[:created_at].lt(params[:range][:end_date])) if params[:range] and params[:range][:end_date]
contracts = contracts.order(Contract.arel_table[:created_at].desc)
# computing total_entries with count(distinct: true) explicitly, because default contracts.count used by paginate plugin seems to override the DISTINCT option and thus returns wrong result. See https://stackoverflow.com/questions/7939719/will-paginate-generates-wrong-number-of-page-links
contracts = contracts.paginate(:page => params[:page]||1, :per_page => [(params[:per_page].try(&:to_i) || 20), 100].min, :total_entries => contracts.count(distinct: true)) unless params[:paginate] == "false"
contracts = contracts.paginate(:page => params[:page]||1, :per_page => [(params[:per_page].try(&:to_i) || 20), 100].min, :total_entries => contracts.distinct.count) unless params[:paginate] == "false"
contracts
end

Expand Down

0 comments on commit ce8c7eb

Please sign in to comment.