mysql - Remove deprecated `:distinct` option from `Relation#count` for Rails 4.1 -


code:

checkin_scope.count(:select => "user_id", :distinct => true) 

sql query

select count(distinct `checkins`.`user_id`) count_user_id,           location_id location_id  `checkins` inner join `locations` on `locations`.`id` = `checkins`.`location_id`  `checkins`.`business_id` = 452 , `checkins`.`status` = 'loyalty'      , `locations`.`status` = 'approved' ,     `checkins`.`location_id` in (302825, 302838, 302839, 302901)      , (date(checkins.created_at) between '2014-10-11' , '2014-11-11')  group location_id 

i need remove :distinct => true has been removed in rails 4.1.

ok, solve problem

checkin_scope.count("distinct(checkins.user_id)") 

where checkin_scope method,

def checkin_scope   cscope = @business.checkins.loyalty_punchh.joins(:location).where(:locations => {:status => "approved"}).group(:location_id)   cscope = cscope.for_location(@location) if @location   if @from && @to     cscope = cscope.where("date(checkins.created_at) between ? , ?",@from.to_date,@to.to_date)   end   cscope end 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -