-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set both a default radius and a dynamic radius column in near query #1597
Comments
I don't see a way to do this, so I'm working on a PR. Here's a couple options for the
Optimally I think
I don't think it'd be a breaking change if you still allow the db column as the second argument, but it might be a little confusing to allow both options. |
On second thought, the |
Hey @mnort9, and thanks for this. Can you tell me a little more about when and how you would use this feature? I'm a little confused about the use case for it. |
@alexreisner Sure. An example use case would be assigning leads to sales agents that have different geographic territories. Agents in rural areas might need a larger radius, so a dynamic radius is stored in the db. When a lead needs to be assigned to an agent, we'd want a query like: Find an agent who's territory this lead is in based on the agent's coordinates and (set radius OR the default radius of X miles). The alternative would be to set the default radius for every sales agent in the db, but then if it ever needs to be changed, it needs to be backfilled. It'd be easier to simply set the fallback radius in the db query and can just adjust the query default. |
@mnort9 sorry for the delay here. I've been thinking about this. Thanks for explaining the use case--it makes sense. I think I can merge, but just a couple things first:
|
@alexreisner I think in this case Aside from this though, I think it may be worth considering moving This is a good example that we're having to use keyword arguments like An alternative to consider: Location.near([lat, lng], 25) # Normal usage
Location.near([lat, lng], radius_field: :effective_radius) # With radius column
Location.near([lat, lng], 25, radius_field: :effective_radius) # With radius column and column default This could be backwards compatible to still allow existing implementations to use the second argument as the radius column. Thoughts? |
When using the
near
query and specifying a dynamic radius column, is it possible to also set a default radius if the dynamic radius is not set for that row?Something like:
Location.near([lat, lng], 25, :effective_radius)
This would be more convenient than setting a default value in the database that might change later.
The text was updated successfully, but these errors were encountered: