3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/spatial_features/has_spatial_features.rb', line 3
def has_spatial_features(options = {})
extend ClassMethods
include InstanceMethods
has_many :features, lambda { extending FeaturesAssociationExtensions }, :as => :spatial_model, :dependent => :delete_all
scope :with_features, lambda { joins(:features).uniq }
scope :without_features, lambda { joins("LEFT OUTER JOIN features ON features.spatial_model_type = '#{name}' AND features.spatial_model_id = #{table_name}.id").where("features.id IS NULL") }
scope :with_stale_spatial_cache, lambda { joins(:spatial_cache).where("#{table_name}.features_hash != spatial_caches.features_hash").uniq } if has_spatial_features_hash?
has_many :spatial_cache, :as => :spatial_model, :dependent => :delete_all
has_many :model_a_spatial_proximities, :as => :model_a, :class_name => 'SpatialProximity', :dependent => :delete_all
has_many :model_b_spatial_proximities, :as => :model_b, :class_name => 'SpatialProximity', :dependent => :delete_all
after_save :update_features_area, :if => :features_hash_changed? if has_features_area? && has_spatial_features_hash?
delegate :has_spatial_features_hash?, :has_features_area?, :to => self
end
|