diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-07-07 14:52:09 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-07-07 14:56:30 +0100 |
commit | d8ca791f48ea096d0e19bdc0ef1d021764a79f20 (patch) | |
tree | 93671ec03299313d3c81e3a2c119ad171e769a4d /activerecord | |
parent | d4f59783d22d573a2ebbd4fc66024efbb122ba98 (diff) | |
download | rails-d8ca791f48ea096d0e19bdc0ef1d021764a79f20.tar.gz rails-d8ca791f48ea096d0e19bdc0ef1d021764a79f20.tar.bz2 rails-d8ca791f48ea096d0e19bdc0ef1d021764a79f20.zip |
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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 5 |
1 files changed, 1 insertions, 4 deletions
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(', ')}]>" |