diff options
author | Alexey Noskov <alexey.noskov@gmail.com> | 2013-05-14 17:44:32 +0400 |
---|---|---|
committer | Alexey Noskov <alexey.noskov@gmail.com> | 2013-05-14 17:44:32 +0400 |
commit | 9b66187622453679497ad2fed4f333e2fca32150 (patch) | |
tree | 5eb14fe537d0f7de4c590aa1bddc1ea650275d5d /activerecord/lib | |
parent | e100d1e489a9d88e86510fcc8f1bdfe0fb54f6a7 (diff) | |
download | rails-9b66187622453679497ad2fed4f333e2fca32150.tar.gz rails-9b66187622453679497ad2fed4f333e2fca32150.tar.bz2 rails-9b66187622453679497ad2fed4f333e2fca32150.zip |
Support array as root element in JSON
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/cast.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index a9ef11aa83..a73f0ac57f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -60,7 +60,7 @@ module ActiveRecord end def json_to_string(object) - if Hash === object + if Hash === object || Array === object ActiveSupport::JSON.encode(object) else object diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 40a3b82839..e9daa5d7ff 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -30,6 +30,7 @@ module ActiveRecord when Array case sql_type when 'point' then super(PostgreSQLColumn.point_to_string(value)) + when 'json' then super(PostgreSQLColumn.json_to_string(value)) else if column.array "'#{PostgreSQLColumn.array_to_string(value, column, self).gsub(/'/, "''")}'" @@ -98,6 +99,7 @@ module ActiveRecord when Array case column.sql_type when 'point' then PostgreSQLColumn.point_to_string(value) + when 'json' then PostgreSQLColumn.json_to_string(value) else return super(value, column) unless column.array PostgreSQLColumn.array_to_string(value, column, self) |