app/models/feature.rb in spatial_features-2.17.2 vs app/models/feature.rb in spatial_features-2.17.3

- old
+ new

@@ -7,10 +7,12 @@ has_one :aggregate_feature, lambda { |feature| where(:spatial_model_type => feature.spatial_model_type) }, :foreign_key => :spatial_model_id, :primary_key => :spatial_model_id validates_inclusion_of :feature_type, :in => FEATURE_TYPES + before_save :truncate_name + after_save :refresh_aggregate, if: :automatically_refresh_aggregate? # Features are used for display so we also cache their KML representation def self.cache_derivatives(options = {}) super @@ -57,7 +59,15 @@ def automatically_refresh_aggregate? # Check if there is a spatial model id because nothing prevents is from creating a Feature without one. Depending on # how you assign a feature to a record, you may end up saving it before assigning it to a record, thereby leaving # this field blank. spatial_model_id? && automatically_refresh_aggregate && saved_change_to_geog? + end + + private + + def truncate_name + return unless name? + col_size = Feature.columns_hash["name"]&.limit || 255 + self.name = name.to_s.truncate(col_size) end end