aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-06-29 14:49:24 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-06-29 14:49:24 -0700
commit7a52d6bba0f3db1d1f145e80d161446668393410 (patch)
treec369850dc181114f8961fae5fbdddcf425d3f484 /activerecord
parent374958b6debd03f5ce4dc0bd2071f3bc9baef330 (diff)
parent314d5579ab63ed9606d25a59cb4010be85fb3b17 (diff)
downloadrails-7a52d6bba0f3db1d1f145e80d161446668393410.tar.gz
rails-7a52d6bba0f3db1d1f145e80d161446668393410.tar.bz2
rails-7a52d6bba0f3db1d1f145e80d161446668393410.zip
Merge pull request #15983 from sgrif/sg-inline-point
Use the type object when sending point columns to the DB
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/cast.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb12
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)