aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-03 15:52:35 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-03 15:53:03 -0500
commit4b6709e818177792735e99a70ec03210c0ac38dc (patch)
treec351e5643be6e670d47d4204c47c798aa9bf7d32 /activerecord/lib/active_record/core.rb
parentbc87cd7f18373c0cde87c088c410fb2bf50969a9 (diff)
downloadrails-4b6709e818177792735e99a70ec03210c0ac38dc.tar.gz
rails-4b6709e818177792735e99a70ec03210c0ac38dc.tar.bz2
rails-4b6709e818177792735e99a70ec03210c0ac38dc.zip
Raise ArgumentError when a instance of ActiveRecord::Base is passed to
find and exists?
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r--activerecord/lib/active_record/core.rb14
1 files changed, 5 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 8f2a48ae2e..5d0f82130d 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -171,23 +171,19 @@ module ActiveRecord
return super if block_given? ||
primary_key.nil? ||
scope_attributes? ||
- columns_hash.include?(inheritance_column) ||
- ids.first.kind_of?(Array)
+ columns_hash.include?(inheritance_column)
id = ids.first
- if ActiveRecord::Base === id
- id = id.id
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- You are passing an instance of ActiveRecord::Base to `find`.
- Please pass the id of the object by calling `.id`.
- MSG
- end
+
+ return super if id.kind_of?(Array) ||
+ id.is_a?(ActiveRecord::Base)
key = primary_key
statement = cached_find_by_statement(key) { |params|
where(key => params.bind).limit(1)
}
+
record = statement.execute([id], self, connection).first
unless record
raise RecordNotFound.new("Couldn't find #{name} with '#{primary_key}'=#{id}",