Module: ActiveRecordSpatial::Associations::ClassMethods

Defined in:
lib/activerecord-spatial/associations.rb,
lib/activerecord-spatial/associations/base.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#has_many_spatially(name, scope = nil, **options, &extension) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/activerecord-spatial/associations.rb', line 10

def has_many_spatially(name, scope = nil, **options, &extension)
  options = build_options(options)

  unless ActiveRecordSpatial::SpatialScopeConstants::RELATIONSHIPS.include?(options[:relationship].to_s)
    raise ArgumentError, %{Invalid spatial relationship "#{options[:relationship]}", expected one of #{ActiveRecordSpatial::SpatialScopeConstants::RELATIONSHIPS.inspect}}
  end

  reflection = ActiveRecord::Associations::Builder::Spatial.build(self, name, scope, options, &extension)

  ActiveRecord::Reflection.add_reflection(self, name, reflection)
end