-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Geocoder produces PG::SyntaxError on rails 4.1 for count queries #630
Comments
+1 Oddly this issue only seems to arise for me when adding distance parameters greater > 10. |
+1 happens for me with postgres and sqlite, same as @mswart described. |
+1 I have the same problem. I am also using Rails 4.1.0 and Ruby 2.0 |
To everyone experiencing this bug: I believe this is a result of this change in Rails 4.1. Can you please confirm that using |
@alexreisner Yes works (with example app + real app):
|
Just tried it. Any tips on how to make this work with https://github.com/mislav/will_paginate |
Thanks guys, I'm closing this. @cyrusstoller I don't use will_paginate so I'm not sure what the problem is, but it's possible that gem is similarly calling |
@alexreisner It is not possible to adjust the implementation of the near scope accordingly? Because other scopes that apply only ordering and filtering still works in rails 4.1. Of cause sometimes you want the distance for every objects in the collection, but there are also many use cases where the reason the apply the near scope is only to filter and/or order the collection. Maybe an optional parameter that specify whether the distance from every record is needed?
|
@mswart true, although to order the collection you need the SELECT clause. If we're talking about only selecting objects within a given radius and we don't care about how far away they are from the center then removing the SELECT clause fixes the |
@alexreisner fair enough. Thanks for tracking this down! |
@alexreisner Would it be ok to add an
(Distance is not calculated as one additional column, but instead directly in the order clause) With this approach only the place where the scope is applied needs to be changed, and not every place, where a given scope is neither counted or normal used. Additional to Alternative I could try to provide a PR. |
@mswart an |
Rails 4.1 does not drop added selection columns on count queries (only on .count(:all)). This parameter adjusts the scope in the way that the records are filtered and ordered by distance but the distance is not select separatly. So .count still works with rails 4.1. Addition to alexreisner#630
I´m getting this issue in a plain RSpec controller test
|
@cyrusstoller wondering if you got it working with will_paginate? |
@victorngkp unfortunately I haven't. I'm still running rails 4.0.5 because of this. |
I’m running into this exact same issue with a |
@alexreisner Oh, yes. That’s exactly what I’m running into—sorry, I had a look for existing issues for that, but I obviously missed it. Thanks! |
[#107064082] Due to the update to Rails 4.1, Geocoder has a issue with regards to its SQL composition. This causes a syntax error to Geocoder's Location-based queries. Issue can be found here: alexreisner/geocoder#630
Here you can find the ”count” part in the readme - https://github.com/alexreisner/geocoder#rails-41-note |
I'm getting this same error in rails 4.2 even with the argument as suggested. |
I have this (or related) issue when i upgrade from rails 5.1 to 5.2 or higher, and the count(:all) solution does not work, because a call limit after the near statement:
|
After upgrade to rails 4.1 Geocoder fails to count the number of results when searching by distance. I have reproduced it with a very simple example:
In Rails 4.0.4 was
Normal query work still in 4.1.0:
Model:
Schema:
Tested with
ruby 2.1
rails 4.1.0 (worked with rails 4.0.4)
geocoder 1.1.9 and master @2a29613acda2468e23056921cc257252d2128ea8
postgresql 9.1
The text was updated successfully, but these errors were encountered: