Exception: Parse::NPlusOneQueryError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/parse/query/n_plus_one_detector.rb

Overview

Exception raised when N+1 query is detected in strict mode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_class, association, target_class, count, location = nil) ⇒ NPlusOneQueryError

Returns a new instance of NPlusOneQueryError.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/parse/query/n_plus_one_detector.rb', line 11

def initialize(source_class, association, target_class, count, location = nil)
  @source_class = source_class
  @association = association
  @target_class = target_class
  @count = count
  @location = location

  message = "N+1 query detected on #{source_class}.#{association} " \
            "(#{count} separate fetches for #{target_class})"
  message += " at #{location}" if location
  message += ". Use `.includes(:#{association})` to eager-load this association."
  super(message)
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



9
10
11
# File 'lib/parse/query/n_plus_one_detector.rb', line 9

def association
  @association
end

#countObject (readonly)

Returns the value of attribute count.



9
10
11
# File 'lib/parse/query/n_plus_one_detector.rb', line 9

def count
  @count
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/parse/query/n_plus_one_detector.rb', line 9

def location
  @location
end

#source_classObject (readonly)

Returns the value of attribute source_class.



9
10
11
# File 'lib/parse/query/n_plus_one_detector.rb', line 9

def source_class
  @source_class
end

#target_classObject (readonly)

Returns the value of attribute target_class.



9
10
11
# File 'lib/parse/query/n_plus_one_detector.rb', line 9

def target_class
  @target_class
end