aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/string.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type/string.rb')
-rw-r--r--activerecord/lib/active_record/type/string.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb
index 3b1554bd5a..cf95e25be0 100644
--- a/activerecord/lib/active_record/type/string.rb
+++ b/activerecord/lib/active_record/type/string.rb
@@ -5,6 +5,22 @@ module ActiveRecord
:string
end
+ def changed_in_place?(raw_old_value, new_value)
+ if new_value.is_a?(::String)
+ raw_old_value != new_value
+ end
+ end
+
+ def type_cast_for_database(value)
+ case value
+ when ::Numeric, ActiveSupport::Duration then value.to_s
+ when ::String then ::String.new(value)
+ when true then "t"
+ when false then "f"
+ else super
+ end
+ end
+
def text?
true
end
@@ -13,9 +29,10 @@ module ActiveRecord
def cast_value(value)
case value
- when true then "1"
- when false then "0"
- else value.to_s
+ when true then "t"
+ when false then "f"
+ # String.new is slightly faster than dup
+ else ::String.new(value.to_s)
end
end
end