diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-19 10:20:58 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-19 14:11:58 +0900 |
commit | f814585bb269f1dd2c275d6ae95d94d8e91d8061 (patch) | |
tree | 0283addf37e75bac629533efbbfaeba9dceb7bdf /activerecord/lib/active_record/log_subscriber.rb | |
parent | 5a302bf553af0e6fedfc63299fc5cd6e79599ef3 (diff) | |
download | rails-f814585bb269f1dd2c275d6ae95d94d8e91d8061.tar.gz rails-f814585bb269f1dd2c275d6ae95d94d8e91d8061.tar.bz2 rails-f814585bb269f1dd2c275d6ae95d94d8e91d8061.zip |
Pass `type_casted_binds` to log subscriber for logging bind values properly
Address to https://github.com/rails/rails/commit/5a302bf553af0e6fedfc63299fc5cd6e79599ef3#commitcomment-18288388.
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 37a092d7a2..c4998ba686 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -20,18 +20,14 @@ module ActiveRecord @odd = false end - def render_bind(attribute) - value = if attribute.type.binary? && attribute.value - if attribute.value.is_a?(Hash) - "<#{attribute.value_for_database.to_s.bytesize} bytes of binary data>" - else - "<#{attribute.value.bytesize} bytes of binary data>" - end + def render_bind(attr, type_casted_value) + value = if attr.type.binary? && attr.value + "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" else - type_cast(attribute.value_for_database) + type_casted_value end - [attribute.name, value] + [attr.name, value] end def sql(event) @@ -48,7 +44,9 @@ module ActiveRecord binds = nil unless (payload[:binds] || []).empty? - binds = " " + payload[:binds].map { |attr| render_bind(attr) }.inspect + binds = " " + payload[:binds].zip(payload[:type_casted_binds]).map { |attr, value| + render_bind(attr, value) + }.inspect end name = colorize_payload_name(name, payload[:name]) @@ -91,10 +89,6 @@ module ActiveRecord def logger ActiveRecord::Base.logger end - - def type_cast(value) - ActiveRecord::Base.connection.type_cast(value) - end end end |