diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-29 15:44:41 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-29 15:44:41 -0600 |
commit | 314d5579ab63ed9606d25a59cb4010be85fb3b17 (patch) | |
tree | 90615d58412b22d391773aec356fb0258b54ef84 /activerecord/lib/active_record | |
parent | d9827ca49fdfc4f1771a3644e737dd67e2e168c3 (diff) | |
download | rails-314d5579ab63ed9606d25a59cb4010be85fb3b17.tar.gz rails-314d5579ab63ed9606d25a59cb4010be85fb3b17.tar.bz2 rails-314d5579ab63ed9606d25a59cb4010be85fb3b17.zip |
Use the type object when sending point columns to the DB
Diffstat (limited to 'activerecord/lib/active_record')
3 files changed, 9 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index b0a161ff32..95fc461bae 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -2,14 +2,6 @@ module ActiveRecord module ConnectionAdapters module PostgreSQL module Cast # :nodoc: - def point_to_string(point) # :nodoc: - "(#{number_for_point(point[0])},#{number_for_point(point[1])})" - end - - def number_for_point(number) - number.to_s.gsub(/\.0$/, '') - end - def hstore_to_string(object, array_member = false) # :nodoc: if Hash === object string = object.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(', ') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb index 9b6494867f..bac8b01d6b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb @@ -25,11 +25,17 @@ module ActiveRecord def type_cast_for_database(value) if value.is_a?(::Array) - PostgreSQLColumn.point_to_string(value) + "(#{number_for_point(value[0])},#{number_for_point(value[1])})" else super end end + + private + + def number_for_point(number) + number.to_s.gsub(/\.0$/, '') + end end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 2818633495..07171a75d5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -28,11 +28,7 @@ module ActiveRecord super end when Array - case sql_type - when 'point' then super(PostgreSQLColumn.point_to_string(value)) - else - super(value, array_column(column)) - end + super(value, array_column(column)) when Hash case sql_type when 'hstore' then super(PostgreSQLColumn.hstore_to_string(value), column) @@ -88,11 +84,7 @@ module ActiveRecord super(value, column) end when Array - case column.sql_type - when 'point' then PostgreSQLColumn.point_to_string(value) - else - super(value, array_column(column)) - end + super(value, array_column(column)) when Hash case column.sql_type when 'hstore' then PostgreSQLColumn.hstore_to_string(value, array_member) |