Class: ActiveRecord::Associations::SpatialAssociationScope

Inherits:
AssociationScope
  • Object
show all
Defined in:
lib/activerecord-spatial/associations/active_record.rb

Overview

:nodoc:

Constant Summary collapse

INSTANCE =
create

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scope(association, connection) ⇒ Object



59
60
61
# File 'lib/activerecord-spatial/associations/active_record.rb', line 59

def scope(association, connection)
  INSTANCE.scope(association, connection)
end

Instance Method Details

#last_chain_scope(scope, table, reflection, owner, assoc_klass) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/activerecord-spatial/associations/active_record.rb', line 64

def last_chain_scope(scope, table, reflection, owner, assoc_klass)
  geom_options = {
    class: assoc_klass
  }

  if reflection.geom.is_a?(Hash)
    geom_options[:value] = owner[reflection.geom[:name]]
    geom_options.merge!(reflection.geom)
  else
    geom_options[:value] = owner[reflection.geom]
    geom_options[:name] = reflection.geom
  end

  scope = scope.send("st_#{reflection.relationship}", geom_options, reflection.scope_options)

  if reflection.type
    polymorphic_type = transform_value(owner.class.base_class.name)
    scope = scope.where(table.name => { reflection.type => polymorphic_type })
  end

  scope
end