diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-16 11:38:24 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-16 11:38:24 -0700 |
commit | 7816b9852b813545a239be53afdd2dc379229614 (patch) | |
tree | 057f095af14cbb46b5abf75e5cc8d5361eec6143 /activerecord/lib | |
parent | c9d75e0814a3fa5797c58e3d98f76fa2990c5b5f (diff) | |
parent | 9b66187622453679497ad2fed4f333e2fca32150 (diff) | |
download | rails-7816b9852b813545a239be53afdd2dc379229614.tar.gz rails-7816b9852b813545a239be53afdd2dc379229614.tar.bz2 rails-7816b9852b813545a239be53afdd2dc379229614.zip |
Merge pull request #10619 from alno/top_level_array_in_postgres_json
Support array as root element in Postgresql JSON columns
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) |