Module: ActiveRecord::ConnectionAdapters::PostGIS::TableDefinition
- Included in:
- SpatialTableDefinition
- Defined in:
- lib/active_record/connection_adapters/postgis/table_definition.rb
Instance Method Summary collapse
-
#new_column_definition(name, type, **options) ⇒ Object
Override new_column_definition to handle spatial column options.
Instance Method Details
#new_column_definition(name, type, **options) ⇒ Object
Override new_column_definition to handle spatial column options
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/postgis/table_definition.rb', line 17 def new_column_definition(name, type, **) col_type = if type.to_sym == :virtual [:type] else type end if spatial_column_type?(col_type) if (limit = .delete(:limit)) && limit.is_a?(::Hash) .merge!(limit) end # Set geographic option for geography types if col_type.to_sym == :st_geography || col_type.to_sym == :geography [:geographic] = true end geo_type = ColumnDefinitionUtils.geo_type([:type] || type) base_type = determine_base_type(col_type, ) # Create hash format limit for column metadata spatial_limit = {} spatial_limit[:type] = col_type.to_s spatial_limit[:srid] = [:srid] if [:srid] && [:srid] != ([:geographic] ? 4326 : 0) spatial_limit[:has_z] = [:has_z] if [:has_z] spatial_limit[:has_m] = [:has_m] if [:has_m] spatial_limit[:geographic] = [:geographic] if [:geographic] # Use hash format as limit for spatial columns, string format for SQL generation [:limit] = spatial_limit.empty? ? nil : spatial_limit [:spatial_type] = geo_type [:spatial_sql] = ColumnDefinitionUtils.(geo_type, ) column = super(name, base_type, **) else column = super(name, type, **) end column end |