aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorDamien Mathieu <42@dmathieu.com>2012-07-06 16:53:33 +0200
committerDamien Mathieu <42@dmathieu.com>2012-07-06 20:04:38 +0200
commit7d0053e6a716be6345daa5e49dceda27ba8dfdb6 (patch)
treecdc268f748bf4426bb751dff41c18112193b06de /activerecord/lib/active_record/relation.rb
parent717aa92dd3f75dec04652940d5571ab34a2f79c3 (diff)
downloadrails-7d0053e6a716be6345daa5e49dceda27ba8dfdb6.tar.gz
rails-7d0053e6a716be6345daa5e49dceda27ba8dfdb6.tar.bz2
rails-7d0053e6a716be6345daa5e49dceda27ba8dfdb6.zip
Limit the number of records in Relation#inspect
While it's interesting to have the results array, it can make a console or a webpage freeze if there are a lot of them. So this limits the number of records displayed in #inspect to 10 and tells how much were effectively found.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 7725331694..dc00448dff 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -515,7 +515,19 @@ module ActiveRecord
end
def inspect
- "#<#{self.class.name} #{to_a.inspect}>"
+ text = if limit_value && limit_value <= 10
+ to_a.inspect
+ else
+ entries = limit(11).to_a
+ if entries.size > 10
+ entries.pop
+ "[#{entries.map(&:inspect).join(', ')}, ...]"
+ else
+ entries.inspect
+ end
+ end
+
+ "#<#{self.class.name} #{text}>"
end
private