From 21675fdc441e5d67dd6bc007979523db164a5b2d Mon Sep 17 00:00:00 2001 From: Trung Duc Tran Date: Sun, 3 Jul 2016 21:27:37 +0200 Subject: Serialize JSON attribute value nil as SQL NULL, not JSON 'null' Test: JSON attribute value nil can be used in where(attr: nil) Add changelog entry --- activerecord/lib/active_record/type/internal/abstract_json.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/type/internal/abstract_json.rb b/activerecord/lib/active_record/type/internal/abstract_json.rb index 513c938088..e19c5a14da 100644 --- a/activerecord/lib/active_record/type/internal/abstract_json.rb +++ b/activerecord/lib/active_record/type/internal/abstract_json.rb @@ -17,7 +17,11 @@ module ActiveRecord end def serialize(value) - ::ActiveSupport::JSON.encode(value) + if value.nil? + nil + else + ::ActiveSupport::JSON.encode(value) + end end def accessor -- cgit v1.2.3