Reputation: 63
I have a function that takes all the results from the model and returns and gets passed to .near()
method to get the closest results. Thing is that I do not store the latitude and longitude on that table. I use the Profile's lat/lng to display results
My method is looking for the Datings
table lat/lng for the .near()
method and I need it to look at the Profiles
lat/lng instead.
Here is what I have so far.
@results = Dating.all
.where("datings.open_to_dating = true")
.where("datings.identity = ?", @category )
.where("datings.deleted_at is null")
.joins("INNER JOIN users on datings.user_id = users.id")
.joins("INNER JOIN profiles on datings.user_id = profiles.user_id")
distance = 75
@results = filter_search_results_by_distance(@results, lat, lng, distance)
def filter_search_results_by_distance(results, lat, lng, distance)
results = results
.joins("INNER JOIN users on datings.user_id = users.id")
.joins("INNER JOIN profiles on datings.user_id = profiles.user_id")
.near([lat, lng], distance, units: :km) # 20 Miles
.order("distance")
end
I'm trying to do a join and possibly do a profiles.near([lat,lng]
.
Upvotes: 0
Views: 131