aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDan Fitch <dgfitch@gmail.com>2019-04-09 12:22:05 -0500
committerDan Fitch <dgfitch@gmail.com>2019-04-09 12:22:05 -0500
commit2e117c8a0b1220137d4a4cee577b4237aedf5c8b (patch)
treeb7e281ccd0ebe075edc38d5a0959d862bc88becd /activerecord
parentdd58d040b2b798105b95e21396e86266bfd40de9 (diff)
downloadrails-2e117c8a0b1220137d4a4cee577b4237aedf5c8b.tar.gz
rails-2e117c8a0b1220137d4a4cee577b4237aedf5c8b.tar.bz2
rails-2e117c8a0b1220137d4a4cee577b4237aedf5c8b.zip
Clarify exists check in logs
The default log messages for Model.exists?, when called from .save on an object which uses scoped uniqueness validation like: class Example < ApplicationRecord validates :field, uniqueness: {scope: parent_id} end can result in slightly misleading logs. An example case: ↳ app/controllers/example_controller.rb:23 (0.2ms) begin transaction ↳ app/controllers/example_controller.rb:39 Example Exists (0.2ms) SELECT 1 AS one FROM "examples" WHERE "examples"."field" IS NULL AND "examples"."parent_id" = ? LIMIT ? [["parent_id", 123], ["LIMIT", 1]] ↳ app/controllers/example_controller.rb:39 (0.1ms) rollback transaction To me, a Rails newbie, this parsed as the following: - started the transaction to create a thing - found that your object exists already! - so we rolled back the transaction (even though the actual cause of the transaction is something that happens after the Exists check.) All this does is add a question mark to the message, to make it clear in the log that this is a check, not a confirmation. This may be kind of silly, but it may save some future goofs by newbs like me.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index fcb0da1a42..9450e4d3c5 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -314,7 +314,7 @@ module ActiveRecord
relation = construct_relation_for_exists(conditions)
- skip_query_cache_if_necessary { connection.select_one(relation.arel, "#{name} Exists") } ? true : false
+ skip_query_cache_if_necessary { connection.select_one(relation.arel, "#{name} Exists?") } ? true : false
end
# This method is called whenever no records are found with either a single