From 7d0053e6a716be6345daa5e49dceda27ba8dfdb6 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Fri, 6 Jul 2012 16:53:33 +0200 Subject: 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. --- activerecord/lib/active_record/relation.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/relation.rb') 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 -- cgit v1.2.3