From d8ca791f48ea096d0e19bdc0ef1d021764a79f20 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 7 Jul 2012 14:52:09 +0100 Subject: Load all records in Relation#inspect A test was failing due to the way that Relation#inspect causes association proxies to ignore unsaved records added to the association. This is fixed by simply calling to_a and letting to_a figure out how to get the records (which, in the case of associations, takes into account new records). I think it is acceptable to do this rather than limiting the query at the database level: * It's what we've done in all released Rails versions up to this point * The goal of the limit is to not flood the console with output - this is the problem we're targeting, rather than the actual loading of the records from the database * You probably want to do something with those records later anyway, otherwise you wouldn't have built a relation for them. --- activerecord/lib/active_record/relation.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a39328b89b..dd1f77e925 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -515,10 +515,7 @@ module ActiveRecord end def inspect - limit = [limit_value, 11].compact.min - entries = loaded? ? to_a.take(limit) : limit(limit) - - entries.map!(&:inspect) + entries = to_a.take([limit_value, 11].compact.min).map!(&:inspect) entries[10] = '...' if entries.size == 11 "#<#{self.class.name} [#{entries.join(', ')}]>" -- cgit v1.2.3