Class: LintFu::Plugins::Rails::BuggyEagerLoad
- Inherits:
-
Issue
- Object
- Issue
- LintFu::Plugins::Rails::BuggyEagerLoad
show all
- Defined in:
- lib/lint_fu/plugins/rails/buggy_eager_load_checker.rb
Instance Attribute Summary
Attributes inherited from Issue
#confidence, #file, #sexp
Instance Method Summary
collapse
Methods inherited from Issue
#brief, #file_basename, #issue_hash, #line, #relative_file
Constructor Details
#initialize(scan, file, sexp, subject) ⇒ BuggyEagerLoad
4
5
6
7
|
# File 'lib/lint_fu/plugins/rails/buggy_eager_load_checker.rb', line 4
def initialize(scan, file, sexp, subject)
super(scan, file, sexp)
@subject = subject
end
|
Instance Method Details
#detail ⇒ Object
9
10
11
|
# File 'lib/lint_fu/plugins/rails/buggy_eager_load_checker.rb', line 9
def detail
"Instances of the paranoid model <code>#{@subject}</code> are being eager-loaded. This may cause unexpected results."
end
|
#reference_info ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/lint_fu/plugins/rails/buggy_eager_load_checker.rb', line 13
def reference_info
return <<EOF
h4. What is it?
A buggy eager load happens when an ActiveRecord finder performs eager loading of a @:has_many@ association and the "target" of the association acts as paranoid.
The acts_as_paranoid plugin does not correctly handle eager loads that use a @JOIN@ strategy. If a paranoid model is eager loaded in this way, _all_ models -- even deleted ones -- will be loaded.
h4. When does it happen?
A finder with any of the following properties will cause Rails to eager-load using @JOIN@
* complex @:conditions@ option (containing SQL fragments, or referring to tables using strings)
* complex @:order@
* complex @:join@
* complex @:include@
* use of named scopes (which almost always add complex options to the query)
If your find exhibits any of these properties and it @:include@s a paranoid model, then you have a problem.
h4. How do I fix it?
Avoid doing complex finds at the same time you @:include@ a paranoid model.
EOF
end
|