module Bullet module Detector class NPlusOneQuery < Association extend Dependency extend StackTraceFilter class < associations already exists in object_associations. def association?(object, associations) value = object_associations[object.bullet_key] if value value.each do |v| # associations == v comparision order is important here because # v variable might be a squeel node where :== method is redefined, # so it does not compare values at all and return unexpected results result = v.is_a?(Hash) ? v.key?(associations) : associations == v return true if result end end false end private def create_notification(callers, klazz, associations) notify_associations = Array(associations) - Bullet.get_whitelist_associations(:n_plus_one_query, klazz) if notify_associations.present? notice = Bullet::Notification::NPlusOneQuery.new(callers, klazz, notify_associations) Bullet.notification_collector.add(notice) end end end end end end