-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#by_distance, #distance_to etc. should not include objects with no location set #73
Comments
Hello, can anybody reproduce this problem? I tried to find the cause but so far I wasn't successful. Please try to reproduce it so I at least know that this is a real bug. Then I'll try to fix it and provide a pull request. Thanks! |
Is nobody at all interested in this bug? There's a very trivial test - just add another location in both |
I fixed a similar problem by creating a new initializer in rails: module Geokit::ActsAsMappable
module ClassMethods
def within(distance, options = {})
options[:within] = distance
where("#{lat_column_name} IS NOT NULL AND #{lng_column_name} IS NOT NULL").
where(distance_conditions(options))
end
end
end You could probably add something like that for distance_to as well |
I can confirm that when using by_distance I am getting objects that have nil lat and/or long |
If someone can write a basic test (look at existing tests and it should be fairly simple) and then take @dipth's good start code as part of overriding the within method (and perhaps related methods) I'm happy to merge (provided it passes the tests) |
@mnoack I though i would try and poke around but i can't seem to get the tests to run:
|
I see you are using Ruby 2.1.6 - To make things easier on me/others trying to replicate your problem can you use the latest e.g. 2.1.6 or latest 2.2 as that's all we test on travis-ci.org and locally. Even if you can't can you past your Gemfile.lock so I can be using the exact same versions of all your gems and debug this. Also I would recommend trying a "bundle update" to get the latest gems versions as that's what travis/myself tends to use. |
Upgraded to Ruby 2.2.2 and rebundled and I got
I tried manually installing:
|
Please provide better documentation about how to run these tests. This is what I have managed so far using Ruby 2.2.2 using postgresql:
Then I got frustrated and rage quit. I am more than willing to help fix this issue. I have a locations table where the lat/long columns are sometimes nil. I have had to work around this by adding: Here are the contents of my
|
It looks like Nothing very interesting happens, but I do see this depreciation warning:
I'm more used to rspec testing. Shouldn't I see more than this output:
With this diff:
|
In my code,
Thing
is anacts_as_mappable
ActiveRecord object:The above works fine. But here is a problem:
It seems that
nil
values for latitude/longitude are treated as being zero. This is wrong.IMHO,
t.distance_to
should returnnil
when either the caller object or the parameter has no location. Also,by_distance
should not include records that have nil lat/long values at all. Everything else makes no sense.This behaviour was in geokit-rails 1.x if I remember correctly.
Can it be restored?
The text was updated successfully, but these errors were encountered: