ryanong / mongoid_spacial

A Mongoid Extention that simplifies and adds support for MongoDB Geo Spacial Calculations.
MIT License
138 stars 63 forks source link

Cannot chain geo_near #13

Open pdelanauze opened 12 years ago

pdelanauze commented 12 years ago

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 commented 12 years ago

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

demersus commented 12 years ago

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

TangMonk commented 9 years ago

same issue

ryanong commented 9 years ago

geo near queries cannot be chained in mongodb

TangMonk commented 9 years ago

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