Skip to content

Commit

Permalink
Load all records in Relation#inspect
Browse files Browse the repository at this point in the history
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
jonleighton committed Jul 7, 2012
1 parent d4f5978 commit d8ca791
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -515,10 +515,7 @@ def values
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(', ')}]>"
Expand Down

0 comments on commit d8ca791

Please sign in to comment.