Skip to content

Commit

Permalink
Fix undefined method error when geometric columns have no srid (ctr…
Browse files Browse the repository at this point in the history
  • Loading branch information
oieioi authored Feb 1, 2022
1 parent 69ab184 commit ecf70d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,9 @@ def get_attributes(column, column_type, klass, options)
# Check out if we got a geometric column
# and print the type and SRID
if column.respond_to?(:geometry_type)
attrs << "#{column.geometry_type}, #{column.srid}"
attrs << [column.geometry_type, column.try(:srid)].compact.join(', ')
elsif column.respond_to?(:geometric_type) && column.geometric_type.present?
attrs << "#{column.geometric_type.to_s.downcase}, #{column.srid}"
attrs << [column.geometric_type.to_s.downcase, column.try(:srid)].compact.join(', ')
end

# Check if the column has indices and print "indexed" if true
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,10 @@ def mock_column(name, type, options = {})
limit: { srid: 4326, type: 'geometry' }),
mock_column(:location, :geography,
geometric_type: 'Point', srid: 0,
limit: { srid: 0, type: 'geometry' })
limit: { srid: 0, type: 'geometry' }),
mock_column(:non_srid, :geography,
geometric_type: 'Point',
limit: { type: 'geometry' })
]
end

Expand All @@ -1182,6 +1185,7 @@ def mock_column(name, type, options = {})
# active :boolean default(FALSE), not null
# geometry :geometry not null, geometry, 4326
# location :geography not null, point, 0
# non_srid :geography not null, point
#
EOS
end
Expand Down

0 comments on commit ecf70d8

Please sign in to comment.