Comments (7)
I can confirm this. My setup:
- geokit-rails 0.1.2
- Ruby 1.9.2
- Database: Postgres
- Models
- Location (
acts_as_mappable
) - PairingSession (
belongs_to :location
,acts_as_mappable :through => :location
)
- Location (
Saying PairingSession.geo_scope(:within => 10, :origin => some_origin)
produced this query:
SELECT *,
(ACOS(least(1,COS(0.699016602649681)*COS(-1.8361509014984057)*COS(RADIANS(locations.lat))*COS(RADIANS(locations.lng))+
COS(0.699016602649681)*SIN(-1.8361509014984057)*COS(RADIANS(locations.lat))*SIN(RADIANS(locations.lng))+
SIN(0.699016602649681)*SIN(RADIANS(locations.lat))))*3963.19)
AS distance FROM "pairing_sessions" WHERE (locations.lat>39.90613128854641 AND locations.lat<40.19527099425359 AND locations.lng>-105.39255977003717 AND locations.lng<-105.01483463996283) AND (
(ACOS(least(1,COS(0.699016602649681)*COS(-1.8361509014984057)*COS(RADIANS(locations.lat))*COS(RADIANS(locations.lng))+
COS(0.699016602649681)*SIN(-1.8361509014984057)*COS(RADIANS(locations.lat))*SIN(RADIANS(locations.lng))+
SIN(0.699016602649681)*SIN(RADIANS(locations.lat))))*3963.19)
<= 10)
which failed with:
PGError: ERROR: missing FROM-clause entry for table "locations"
LINE 2: ...16602649681)*COS(-1.8361509014984057)*COS(RADIANS(locations....
^
Adding a .includes(:location)
to the end of the query correctly added this to the query:
FROM "pairing_sessions" LEFT OUTER JOIN "locations" ON "locations"."id" = "pairing_sessions"."location_id" WHERE ...
from geokit-rails3.
It is definitely possible that making a Model mappable through another one fails.
I know that I've tried to make this work yet. I've just copied the original code.
Unfortunately I don't have the time to do this in the next few weeks/months.
I don't think that you should need to add an include scope in the query chain, geokit-rails3 should do this for you when it notices that you use a :through option. But as I've just said, I'm pretty sure it is not working right now.
If it is something that is important to you, you can fork the repository and try to make this work. I'd be happy to merge a pull request from you (or anyone else) if it has the corresponding tests.
from geokit-rails3.
Cool. I'll do some investigation and let you know.
from geokit-rails3.
I can confirm this same issue. Your workaround works, thanks.
I patched it right in the model by overriding the within method like so:
def self.within(*args)
super(*args).includes(NAME_OF_ASSOCIATION)
end
from geokit-rails3.
Big thanks for that workaround :)
from geokit-rails3.
I have a fix for this in #8.
from geokit-rails3.
Thanks @cbartlett - using your workaround
from geokit-rails3.
Related Issues (20)
- undefined method `acts_as_mappable' HOT 3
- Geokit::ActsAsMappable::UnsupportedAdapter `mysql2` is not a supported adapter. HOT 5
- No generator for geokit:install HOT 1
- How to get way points between two locations HOT 1
- ArgumentError: Unknown key(s): origin HOT 1
- Unknow column distance HOT 1
- Can't install to Rails 3.1 HOT 2
- mutated vowel
- how to get name city ,zipcode by search with a text HOT 2
- Column "distance" does not exist when using Model.where HOT 2
- mongodb, undefined method `acts_as_mappable' for City:Class HOT 2
- url_escape not working well for umlaut characters HOT 1
- undefined method `empty?' for #<Geokit::GeoLoc:0x45ef820>
- ActsAsMappable::distance_sql calls *_distance_sql with incorrect parameters HOT 3
- Math::DomainError
- Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT HOT 1
- sorry, can be closed
- Update to Geokit 1.7 HOT 2
- Distance sorting takes no effect.
- config/initializers/geokit_config.rb not present in gem installation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geokit-rails3.