Open SunnyTam opened 8 years ago
the workaround should be Merchant.joins(:location).within(50,:origin => [lat,lng]) Stack overflow refenerce
Looking for any other solutions for this
any update for this?
I think the through only giving the methods and forget to adding the join if we look at the query
this one that using join
irb(main):002:0> Merchant.joins(:primary_address).by_distance(:origin => [37.792,-122.393])
Merchant Load (6.3ms) SELECT "merchants".* FROM "merchants" INNER JOIN "addresses" ON "addresses"."addressable_id" = "merchants"."id" AND "addresses"."addressable_type" = $1 AND "addresses"."primary" = $2 WHERE (addresses.lat IS NOT NULL AND addresses.lng IS NOT NULL) ORDER BY
(ACOS(least(1,COS(0.6595948309136971)*COS(-2.1361608313934197)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595948309136971)*SIN(-2.1361608313934197)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595948309136971)*SIN(RADIANS(addresses.lat))))*6376.77271)
ASC LIMIT $3 [["addressable_type", "Merchant"], ["primary", true], ["LIMIT", 11]]
this one is not using join
irb(main):003:0> Merchant.by_distance(:origin => [37.792,-122.393])
Merchant Load (2.5ms) SELECT "merchants".* FROM "merchants" WHERE (addresses.lat IS NOT NULL AND addresses.lng IS NOT NULL) ORDER BY
(ACOS(least(1,COS(0.6595948309136971)*COS(-2.1361608313934197)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595948309136971)*SIN(-2.1361608313934197)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595948309136971)*SIN(RADIANS(addresses.lat))))*6376.77271)
ASC LIMIT $1 [["LIMIT", 11]]
I am following the guide to build a merchant model using location model https://github.com/geokit/geokit-rails#using-through Below is my code
I am trying to run
Merchant.within(50,:origin => [lat,lng])
It throw
Is there any wrong setup between model?