diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 20 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 5 |
3 files changed, 20 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 32261ba9e6..ccaa2ad8f1 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -2,11 +2,11 @@ * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to` and `remove_belongs_to` are acceptable. References are reversible. - Examples: + Examples: # Create a user_id column add_reference(:products, :user) - # Create a supplier_id, supplier_type columns and appropriate index + # Create a supplier_id, supplier_type columns and appropriate index add_reference(:products, :supplier, polymorphic: true, index: true) # Remove polymorphic reference remove_reference(:products, :supplier, polymorphic: true) @@ -20,14 +20,16 @@ *Aleksey Magusev* -* `ActiveRelation#inspect` no longer calls `#to_a`. This means that in places - where `#inspect` is implied (such as in the console), creating a relation - will not execute it anymore, you'll have to call `#to_a` when necessary: +* `ActiveRecord::Relation#inspect` now makes it clear that you are + dealing with a `Relation` object rather than an array:. - User.where(:age => 30) # => returns the relation - User.where(:age => 30).to_a # => executes the query and returns the loaded objects, as before + User.where(:age => 30).inspect + # => <ActiveRecord::Relation [#<User ...>, #<User ...>]> - *Brian Cardarella* + User.where(:age => 30).to_a.inspect + # => [#<User ...>, #<User ...>] + + *Brian Cardarella & Jon Leighton* * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later. Example: @@ -865,7 +867,7 @@ * LRU cache in mysql and sqlite are now per-process caches. - * lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache keys are per process id. + * lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache keys are per process id. * lib/active_record/connection_adapters/sqlite_adapter.rb: ditto *Aaron Patterson* diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index e268d451e0..7725331694 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -514,6 +514,10 @@ module ActiveRecord @values.dup end + def inspect + "#<#{self.class.name} #{to_a.inspect}>" + end + private def references_eager_loaded_tables? diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 8544d36aa8..7fdd42f150 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1311,4 +1311,9 @@ class RelationTest < ActiveRecord::TestCase relation.merge! where: 'foo' end end + + test "relations show the records in #inspect" do + relation = Post.limit(2) + assert_equal "#<ActiveRecord::Relation [#{Post.limit(2).map(&:inspect).join(', ')}]>", relation.inspect + end end |