Skip to content

Commit f50f581

Browse files
BuonOmorafiss
authored andcommitted
fix: distinguish enum from spatial column
If an enum name contained a spatial type name (e.g. "point"). It would be matched by a regex as a sql type. This commit is handling that by checking type metadata. See rgeo/activerecord-postgis-adapter#432
1 parent e7c4470 commit f50f581

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/active_record/connection_adapters/cockroachdb/column.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def initialize(name, cast_type, default, sql_type_metadata = nil, null = true,
2727
super(name, cast_type, default, sql_type_metadata, null, default_function,
2828
collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
2929

30-
@geographic = sql_type_metadata.sql_type.match?(/geography\(/i)
3130
@hidden = hidden
3231

32+
return unless spatial?
33+
34+
@geographic = sql_type_metadata.sql_type.match?(/geography\(/i)
35+
3336
if @geographic
3437
# Geographic type information is embedded in the SQL type
3538
@srid = 4326

test/cases/adapters/postgresql/postgis_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ def test_multi_polygon_column
169169
assert_equal wkt, rec.m_poly.to_s
170170
end
171171

172+
def test_spatial_column_matching_enum
173+
SpatialModel.lease_connection.create_enum(:point_type, ["point", "line_string", "polygon"])
174+
SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t|
175+
t.enum "point_type", enum_type: :point_type
176+
t.column "latlon", :st_point, srid: 3785, geographic: true
177+
end
178+
SpatialModel.reset_column_information
179+
_id, enum, geo = SpatialModel.columns
180+
refute_predicate enum, :geographic?
181+
refute_predicate enum, :spatial?
182+
assert_predicate geo, :geographic?
183+
assert_predicate geo, :spatial?
184+
end
185+
172186
private
173187

174188
def klass

0 commit comments

Comments
 (0)