aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/autoloading_and_reloading_constants.md
diff options
context:
space:
mode:
authorKevin Reintjes <kreintjes@gmail.com>2017-02-27 17:45:24 +0100
committerKevin Reintjes <kreintjes@gmail.com>2017-04-06 10:30:33 +0200
commitb4038ab37ac4e869632238071a3d6714a152a0a5 (patch)
treee59e1123d9eca94cbbc924c02b5355aa5d60c4a9 /guides/source/autoloading_and_reloading_constants.md
parent4cc1c14493e7a9bd188ee13c237366f6bc2e13f4 (diff)
downloadrails-b4038ab37ac4e869632238071a3d6714a152a0a5.tar.gz
rails-b4038ab37ac4e869632238071a3d6714a152a0a5.tar.bz2
rails-b4038ab37ac4e869632238071a3d6714a152a0a5.zip
Correct Autoloading and STI guide (issue #26994)
Diffstat (limited to 'guides/source/autoloading_and_reloading_constants.md')
-rw-r--r--guides/source/autoloading_and_reloading_constants.md17
1 files changed, 8 insertions, 9 deletions
diff --git a/guides/source/autoloading_and_reloading_constants.md b/guides/source/autoloading_and_reloading_constants.md
index 61657023e7..05743ee4ce 100644
--- a/guides/source/autoloading_and_reloading_constants.md
+++ b/guides/source/autoloading_and_reloading_constants.md
@@ -983,20 +983,19 @@ WHERE "polygons"."type" IN ("Rectangle")
That is not a bug, the query includes all *known* descendants of `Rectangle`.
A way to ensure this works correctly regardless of the order of execution is to
-load the leaves of the tree by hand at the bottom of the file that defines the
-root class:
+manually load the direct subclasses at the bottom of the file that defines each
+intermediate class:
```ruby
-# app/models/polygon.rb
-class Polygon < ApplicationRecord
+# app/models/rectangle.rb
+class Rectangle < Polygon
end
-require_dependency ‘square’
+require_dependency 'square'
```
-Only the leaves that are **at least grandchildren** need to be loaded this
-way. Direct subclasses do not need to be preloaded. If the hierarchy is
-deeper, intermediate classes will be autoloaded recursively from the bottom
-because their constant will appear in the class definitions as superclass.
+This needs to happen for every intermediate (non-root and non-leaf) class. The
+root class does not scope the query by type, and therefore does not necessarily
+have to know all its descendants.
### Autoloading and `require`