aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-09 01:10:41 +0930
committerGitHub <noreply@github.com>2017-05-09 01:10:41 +0930
commit3f4eeb6dbab04bbc2608aaf51502327cc2d7e62b (patch)
tree948520ccdb2b07b6ae1e71894b4dcc309eab6553 /guides
parent1edecda26efb1c8c0a6953c7dff41ad25ae3de0e (diff)
parentb4038ab37ac4e869632238071a3d6714a152a0a5 (diff)
downloadrails-3f4eeb6dbab04bbc2608aaf51502327cc2d7e62b.tar.gz
rails-3f4eeb6dbab04bbc2608aaf51502327cc2d7e62b.tar.bz2
rails-3f4eeb6dbab04bbc2608aaf51502327cc2d7e62b.zip
Merge pull request #28240 from kreintjes/fix/autoloading-sti-guide
Correct Autoloading and STI guide (issue #26994)
Diffstat (limited to 'guides')
-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`