diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-06 19:44:24 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-06 19:44:24 +0900 |
commit | 9cc463ed7b7be098602b72a98f72220ea6466ba2 (patch) | |
tree | 311386802febb8bd8ecac4e90a93f0e5dfbfa3be /activerecord/lib/active_record/associations/collection_proxy.rb | |
parent | daa264fb5afc353cb044787993b9d9b98f774b26 (diff) | |
parent | 788eb51df3007d94b266965433b0be88a23b84c5 (diff) | |
download | rails-9cc463ed7b7be098602b72a98f72220ea6466ba2.tar.gz rails-9cc463ed7b7be098602b72a98f72220ea6466ba2.tar.bz2 rails-9cc463ed7b7be098602b72a98f72220ea6466ba2.zip |
Merge pull request #35174 from ypresto/fix-concat-retval
Fix `CollectionProxy#concat` to return self by alias it to `#<<`
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_proxy.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 4fbbc713e4..78993cee8a 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -366,34 +366,6 @@ module ActiveRecord @association.create!(attributes, &block) end - # Add one or more records to the collection by setting their foreign keys - # to the association's primary key. Since #<< flattens its argument list and - # inserts each record, +push+ and #concat behave identically. Returns +self+ - # so method calls may be chained. - # - # class Person < ActiveRecord::Base - # has_many :pets - # end - # - # person.pets.size # => 0 - # person.pets.concat(Pet.new(name: 'Fancy-Fancy')) - # person.pets.concat(Pet.new(name: 'Spook'), Pet.new(name: 'Choo-Choo')) - # person.pets.size # => 3 - # - # person.id # => 1 - # person.pets - # # => [ - # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>, - # # #<Pet id: 2, name: "Spook", person_id: 1>, - # # #<Pet id: 3, name: "Choo-Choo", person_id: 1> - # # ] - # - # person.pets.concat([Pet.new(name: 'Brain'), Pet.new(name: 'Benny')]) - # person.pets.size # => 5 - def concat(*records) - @association.concat(*records) - end - # Replaces this collection with +other_array+. This will perform a diff # and delete/add only records that have changed. # @@ -1033,8 +1005,9 @@ module ActiveRecord end # Adds one or more +records+ to the collection by setting their foreign keys - # to the association's primary key. Returns +self+, so several appends may be - # chained together. + # to the association's primary key. Since +<<+ flattens its argument list and + # inserts each record, +push+ and +concat+ behave identically. Returns +self+ + # so several appends may be chained together. # # class Person < ActiveRecord::Base # has_many :pets @@ -1057,6 +1030,7 @@ module ActiveRecord end alias_method :push, :<< alias_method :append, :<< + alias_method :concat, :<< def prepend(*args) raise NoMethodError, "prepend on association is not defined. Please use <<, push or append" |