Merge pull request #106 from Linuus/master
Count unique records in Rails 4
This commit is contained in:
commit
0bb4a41ad0
|
@ -29,8 +29,12 @@ 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 == 4
|
||||||
|
options[:filter] == :all ? imps.count : imps.select(options[:filter]).distinct.count
|
||||||
|
else
|
||||||
options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true)
|
options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_impressionist_counter_cache
|
def update_impressionist_counter_cache
|
||||||
slave = Impressionist::UpdateCounters.new(self)
|
slave = Impressionist::UpdateCounters.new(self)
|
||||||
|
|
Loading…
Reference in New Issue