aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-19 21:16:23 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-20 14:04:50 -0600
commit776af48acb1035e70a326609ec5e5b632ef0c2c5 (patch)
tree5a423c1aee660d7582c766df7b5658c78bd52aa3 /activerecord/lib/active_record/connection_adapters
parent8cb7bc8b55e8054f66cd58840392e6cc63134a90 (diff)
downloadrails-776af48acb1035e70a326609ec5e5b632ef0c2c5.tar.gz
rails-776af48acb1035e70a326609ec5e5b632ef0c2c5.tar.bz2
rails-776af48acb1035e70a326609ec5e5b632ef0c2c5.zip
PostgreSQL hstore types are automatically deserialized from the database.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb4
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 0214154c51..6aa4a2c5b3 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -83,6 +83,7 @@ module ActiveRecord
when :date then klass.value_to_date(value)
when :binary then klass.binary_to_string(value)
when :boolean then klass.value_to_boolean(value)
+ when :hstore then klass.cast_hstore(value)
else value
end
end
@@ -100,6 +101,7 @@ module ActiveRecord
when :date then "#{klass}.value_to_date(#{var_name})"
when :binary then "#{klass}.binary_to_string(#{var_name})"
when :boolean then "#{klass}.value_to_boolean(#{var_name})"
+ when :hstore then "#{klass}.cast_hstore(#{var_name})"
else var_name
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 9802bac87b..563f98dc5e 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -49,6 +49,10 @@ module ActiveRecord
super
end
end
+
+ def cast_hstore(string)
+ Hash[[string.split('=>').map { |k| k[1...-1] }]]
+ end
end
# :startdoc: