Browse files

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.
  • Loading branch information...
1 parent d4f5978 commit d8ca791f48ea096d0e19bdc0ef1d021764a79f20 @jonleighton jonleighton committed Jul 7, 2012
Showing with 1 addition and 4 deletions.
  1. +1 −4 activerecord/lib/active_record/relation.rb
5 activerecord/lib/active_record/relation.rb
@@ -515,10 +515,7 @@ def values
def inspect
- limit = [limit_value, 11].compact.min
- entries = loaded? ? to_a.take(limit) : limit(limit)
+ entries = to_a.take([limit_value, 11].compact.min).map!(&:inspect)
entries[10] = '...' if entries.size == 11
"#<#{} [#{entries.join(', ')}]>"

0 comments on commit d8ca791

Please sign in to comment.