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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/activerecord-spatial/associations.rb', line 9

def has_many_spatially(name, scope = nil, options = {}, &extension)
  if scope.is_a?(Hash)
    options = scope
    scope   = nil
  end

  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)

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

  reflection
end