diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-03-01 12:31:43 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-03-01 12:31:43 -0800 |
commit | 35050ab26dcb99bafc7416c6d8fefd32131352b8 (patch) | |
tree | 05d9f7caf4d422a08aba1a5ab442926805a14b20 /activerecord/lib | |
parent | 99775fd1612217aaba2f3580b4204c6b75c04249 (diff) | |
parent | b9399c470bc7cf85952ab0cc7113f4f825a1a7b3 (diff) | |
download | rails-35050ab26dcb99bafc7416c6d8fefd32131352b8.tar.gz rails-35050ab26dcb99bafc7416c6d8fefd32131352b8.tar.bz2 rails-35050ab26dcb99bafc7416c6d8fefd32131352b8.zip |
Merge pull request #9510 from senny/7364_warn_when_appending_prepending_to_an_association
deal with `#append` and `#prepend` on association collections
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index e93e700c93..543204abac 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -83,9 +83,9 @@ module ActiveRecord # # #<Pet id: 3, name: "Choo-Choo"> # # ] # - # Be careful because this also means you’re initializing a model - # object with only the fields that you’ve selected. If you attempt - # to access a field that is not in the initialized record you’ll + # Be careful because this also means you're initializing a model + # object with only the fields that you've selected. If you attempt + # to access a field that is not in the initialized record you'll # receive: # # person.pets.select(:name).first.person_id @@ -924,7 +924,7 @@ module ActiveRecord alias_method :to_a, :to_ary # 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 + # to the association's primary key. Returns +self+, so several appends may be # chained together. # # class Person < ActiveRecord::Base @@ -947,6 +947,11 @@ module ActiveRecord proxy_association.concat(records) && self end alias_method :push, :<< + alias_method :append, :<< + + def prepend(*args) + raise NoMethodError, "prepend on association is not defined. Please use << or append" + end # Equivalent to +delete_all+. The difference is that returns +self+, instead # of an array with the deleted objects, so methods can be chained. See |