Reputation: 48453
I am working with the Geocoder gem and there is mentioned this snippet for searching records within a distance:
Venue.near('Omaha, NE, US', 20)
This is working well, but I would need to add another condition. This is the query I currently use:
Car.where('car.status = ? AND listings.sold IS ?', 1, nil).includes(:images, :user)
And to this query I am trying to add the near call, like this:
Car.near('90013', 20).('car.status = ? AND listings.sold IS ?', 1, nil).includes(:images, :user)
But result of this query is just nil
.
What is the correct way to combine near query with where condition?
Upvotes: 3
Views: 1690
Reputation: 7070
nearest_location = @company.work_groups.where("level = 1 AND wg_active = 1 AND address IS NOT NULL AND address <> ''").near(employee_location, @company.miles, :order => :distance).first
Here is an example where I'm using the Geocoder gem and a where statement in the same line of code. Hope that it helps.
Upvotes: 1