Skip to content

Commit ecf70d8

Browse files
authored
Fix undefined method error when geometric columns have no srid (#920)
1 parent 69ab184 commit ecf70d8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/annotate/annotate_models.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ def get_attributes(column, column_type, klass, options)
887887
# Check out if we got a geometric column
888888
# and print the type and SRID
889889
if column.respond_to?(:geometry_type)
890-
attrs << "#{column.geometry_type}, #{column.srid}"
890+
attrs << [column.geometry_type, column.try(:srid)].compact.join(', ')
891891
elsif column.respond_to?(:geometric_type) && column.geometric_type.present?
892-
attrs << "#{column.geometric_type.to_s.downcase}, #{column.srid}"
892+
attrs << [column.geometric_type.to_s.downcase, column.try(:srid)].compact.join(', ')
893893
end
894894

895895
# Check if the column has indices and print "indexed" if true

spec/lib/annotate/annotate_models_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,10 @@ def mock_column(name, type, options = {})
11681168
limit: { srid: 4326, type: 'geometry' }),
11691169
mock_column(:location, :geography,
11701170
geometric_type: 'Point', srid: 0,
1171-
limit: { srid: 0, type: 'geometry' })
1171+
limit: { srid: 0, type: 'geometry' }),
1172+
mock_column(:non_srid, :geography,
1173+
geometric_type: 'Point',
1174+
limit: { type: 'geometry' })
11721175
]
11731176
end
11741177

@@ -1182,6 +1185,7 @@ def mock_column(name, type, options = {})
11821185
# active :boolean default(FALSE), not null
11831186
# geometry :geometry not null, geometry, 4326
11841187
# location :geography not null, point, 0
1188+
# non_srid :geography not null, point
11851189
#
11861190
EOS
11871191
end

0 commit comments

Comments
 (0)