Fixed unique count for Rails 4

This commit is contained in:
Linus Pettersson 2013-08-16 23:37:30 +02:00
parent 93f7c6bc2f
commit 36eb6cacb2
1 changed files with 5 additions and 1 deletions

View File

@ -29,7 +29,11 @@ module Impressionist
def impressionist_count(options={}) def impressionist_count(options={})
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date]) imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
if Rails::VERSION::MAJOR == 3
options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true)
else
options[:filter] == :all ? imps.count : imps.select(options[:filter]).distinct.count
end
end end
def update_impressionist_counter_cache def update_impressionist_counter_cache