diff options
author | Akira Matsuda <ronnie@dio.jp> | 2013-01-02 05:07:32 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2013-01-02 05:12:16 +0900 |
commit | 2565c81862a7dc5cc2ab058d7fb25759aab1af7b (patch) | |
tree | 04227c76519baf01d36e0460be7b8fd2f13867a6 /activerecord | |
parent | 44717a9d548c95c7b01e7e0dce061257b3a93646 (diff) | |
download | rails-2565c81862a7dc5cc2ab058d7fb25759aab1af7b.tar.gz rails-2565c81862a7dc5cc2ab058d7fb25759aab1af7b.tar.bz2 rails-2565c81862a7dc5cc2ab058d7fb25759aab1af7b.zip |
find_or_create_by is deprecated in AR 4
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/base.rb | 25 |
2 files changed, 2 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index d8b6d7a86b..d0f5608f68 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -459,7 +459,7 @@ module ActiveRecord # has_many :people do # def find_or_create_by_name(name) # first_name, last_name = name.split(" ", 2) - # find_or_create_by_first_name_and_last_name(first_name, last_name) + # find_or_create_by(first_name: first_name, last_name: last_name) # end # end # end @@ -474,7 +474,7 @@ module ActiveRecord # module FindOrCreateByNameExtension # def find_or_create_by_name(name) # first_name, last_name = name.split(" ", 2) - # find_or_create_by_first_name_and_last_name(first_name, last_name) + # find_or_create_by(first_name: first_name, last_name: last_name) # end # end # diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3d374fe9b4..0a3fdef5a5 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -179,23 +179,6 @@ module ActiveRecord #:nodoc: # # Payment.order("created_on").find_by_amount(50) # - # The same dynamic finder style can be used to create the object if it doesn't already exist. - # This dynamic finder is called with <tt>find_or_create_by_</tt> and will return the object if - # it already exists and otherwise creates it, then returns it. Protected attributes won't be set - # unless they are given in a block. - # - # # No 'Summer' tag exists - # Tag.find_or_create_by_name("Summer") # equal to Tag.create(name: "Summer") - # - # # Now the 'Summer' tag does exist - # Tag.find_or_create_by_name("Summer") # equal to Tag.find_by_name("Summer") - # - # # Now 'Bob' exist and is an 'admin' - # User.find_or_create_by_name('Bob', age: 40) { |u| u.admin = true } - # - # Adding an exclamation point (!) on to the end of <tt>find_or_create_by_</tt> will - # raise an <tt>ActiveRecord::RecordInvalid</tt> error if the new record is invalid. - # # Use the <tt>find_or_initialize_by_</tt> finder if you want to return a new record without # saving it first. Protected attributes won't be set unless they are given in a block. # @@ -203,14 +186,6 @@ module ActiveRecord #:nodoc: # winter = Tag.find_or_initialize_by_name("Winter") # winter.persisted? # false # - # To find by a subset of the attributes to be used for instantiating a new object, pass a hash instead of - # a list of parameters. - # - # Tag.find_or_create_by_name(name: "rails", creator: current_user) - # - # That will either find an existing tag named "rails", or create a new one while setting the - # user that created it. - # # == Saving arrays, hashes, and other non-mappable objects in text columns # # Active Record can serialize any object in text columns using YAML. To do so, you must |