diff options
author | Hendy Tanata <htanata@gmail.com> | 2017-03-28 18:53:58 -0700 |
---|---|---|
committer | Hendy Tanata <htanata@gmail.com> | 2017-03-28 19:40:52 -0700 |
commit | 3d6176fded424a2195e399d031e343bbcd0edcad (patch) | |
tree | 1bf64758cf0ed3cc0387aa2cef163ededa12fd8e /activerecord/lib/active_record/relation.rb | |
parent | 29d6e9cdc4d8528b6676843509347fc8fead935b (diff) | |
download | rails-3d6176fded424a2195e399d031e343bbcd0edcad.tar.gz rails-3d6176fded424a2195e399d031e343bbcd0edcad.tar.bz2 rails-3d6176fded424a2195e399d031e343bbcd0edcad.zip |
Load only needed records on ActiveRecord::Relation#inspect
Instead of loading all records and returning only a subset of those,
just load the records as needed.
Fixes #25537.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 2d6b21bec5..5775eda5a5 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -635,7 +635,9 @@ module ActiveRecord end def inspect - entries = records.take([limit_value, 11].compact.min).map!(&:inspect) + subject = loaded? ? records : self + entries = subject.take([limit_value, 11].compact.min).map!(&:inspect) + entries[10] = "..." if entries.size == 11 "#<#{self.class.name} [#{entries.join(', ')}]>" |