diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-13 11:48:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-13 11:48:07 -0700 |
commit | 7658dc37a40077444fee1eafcf4a59fae1b441a5 (patch) | |
tree | c8bed932dc82fc245f61838fb74d6a3d46f6ae90 /activerecord/lib | |
parent | d99974b27cac1d3ed3af6bef0b7551044a8c9923 (diff) | |
parent | d35f0033c7dec2b8d8b52058fb8db495d49596f7 (diff) | |
download | rails-7658dc37a40077444fee1eafcf4a59fae1b441a5.tar.gz rails-7658dc37a40077444fee1eafcf4a59fae1b441a5.tar.bz2 rails-7658dc37a40077444fee1eafcf4a59fae1b441a5.zip |
Merge branch 'master' into adequaterecord
* master:
passing an instance of an AR object to `find` is deprecated
passing an ActiveRecord object to `exists?` is deprecated.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 9a2900843e..ff0fbe932b 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -370,7 +370,7 @@ module ActiveRecord if record.new_record? include_in_memory?(record) else - loaded? ? target.include?(record) : scope.exists?(record) + loaded? ? target.include?(record) : scope.exists?(record.id) end else false diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 5ebfc318aa..7192aecee1 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + module ActiveRecord module FinderMethods ONE_AS_ONE = '1 AS one' @@ -280,7 +282,12 @@ module ActiveRecord # Person.exists?(false) # Person.exists? def exists?(conditions = :none) - conditions = conditions.id if Base === conditions + if Base === conditions + conditions = conditions.id + ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `exists?`." \ + "Please pass the id of the object by calling `.id`" + end + return false if !conditions relation = apply_join_dependency(self, construct_join_dependency) @@ -412,7 +419,11 @@ module ActiveRecord end def find_one(id) - id = id.id if ActiveRecord::Base === id + if ActiveRecord::Base === id + id = id.id + ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \ + "Please pass the id of the object by calling `.id`" + end column = columns_hash[primary_key] substitute = connection.substitute_at(column, bind_values.length) |