app/models/tracking_cookie.rb in e9_crm-0.1.26 vs app/models/tracking_cookie.rb in e9_crm-0.1.27

- old
+ new

@@ -43,9 +43,25 @@ class TrackingCookie < ActiveRecord::Base belongs_to :user, :inverse_of => :tracking_cookies has_many :page_views after_save :generate_hid, :on => :create + scope :for_users, lambda {|*users| + users.flatten! + users.map!(&:to_param) + users.compact! + + if users.length == 1 + where arel_table[:user_id].eq(users.first) + else + where arel_table[:user_id].in(users) + end + } + + scope :for_user, lambda {|user| + where arel_table[:user_id].in(users.flatten.map(&:to_param)) + } + protected def generate_hid unless hid.present? update_attribute :hid, Digest::MD5.hexdigest("#{id}//#{DateTime.now}")