Skip to content

Cannot chain geo_near #13

@pdelanauze

Description

@pdelanauze

Can we not chain the geo_near query ?

Say we have a scope

scope :enabled, where(:enabled => true)

This chain would work:

def look_for_enabled_close_to
  self.enabled.geo_near([1.0, 1.0], :max_distance => 5, :unit => :km, :spherical => true)
end

This would not, throws a NoMethodError: undefined method `scoped' for #Mongoid::Spacial::GeoNearResults:0x00000105455258

def look_for_enabled_close_to
  self.geo_near([1.0, 1.0], :max_distance => 5, :unit => :km, :spherical => true).enabled
end

Also, wrapping geo_near in a scope results in the same exception being thrown...
e.g.

scope :geo_near_plus_plus, lambda {|coords, rad| geo_near(coords, :max_distance => rad)}

Here's the stack trace

NoMethodError: undefined method `scoped' for #<Mongoid::Spacial::GeoNearResults:0x00000105455258>
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/extensions/proc/scoping.rb:20:in `scoped'
    from (eval):3:in `geo_near_plus_plus'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/criteria.rb:379:in `block in method_missing'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/named_scope.rb:120:in `with_scope'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/criteria.rb:378:in `method_missing'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions