Skip to content

Loading…

Cannot chain geo_near #13

Open
pdelanauze opened this Issue · 5 comments

5 participants

@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'
@cblavier

+1, would be really great if geo_near queries could be chained with scopes

@demersus

This just threw a wrench in one of my search models... +1 Please implement this feature

@TangMonk

same issue

@ryanong
Owner

geo near queries cannot be chained in mongodb

@TangMonk

I am try to using Postgres with Postgis, It seems better than mongodb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.