Git Product home page Git Product logo

Comments (7)

mcmire avatar mcmire commented on May 29, 2024

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)

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.

jlecour avatar jlecour commented on May 29, 2024

@mcmire

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.

mcmire avatar mcmire commented on May 29, 2024

Cool. I'll do some investigation and let you know.

from geokit-rails3.

cbartlett avatar cbartlett commented on May 29, 2024

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.

charliegodsoe avatar charliegodsoe commented on May 29, 2024

Big thanks for that workaround :)

from geokit-rails3.

mcmire avatar mcmire commented on May 29, 2024

I have a fix for this in #8.

from geokit-rails3.

novemberkilo avatar novemberkilo commented on May 29, 2024

Thanks @cbartlett - using your workaround

from geokit-rails3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.