-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
MULTI geoms are bound to sql separately #79
Comments
Maybe fixing this upstream by first checking Otherwise how do we end up sending |
I wasn't sure the implications of setting id_for_database as it is related to the PK. How about adding an multi_geom = RGeo::Geos.factory.parse_wkt("MULTIPOLYGON (((0 0, 0 1, 1 1, 0 0)),((1 1, 0 0, 0 1, 1 1)))")
multi_geom.define_singleton_method(:acts_like_string?) { }
ApplicationRecord.send(:quote_bound_value, multi_geom)
=> "'00200000060000000000000002000000000300000001000000040000000000000000000000000000000000000000000000003ff00000000000003ff00000000000003ff000000000000000000000000000000000000000000000000000000300000001000000043ff00000000000003ff00000000000000000000000000000000000000000000000000000000000003ff00000000000003ff00000000000003ff0000000000000'" I can make a PR. |
Sorry I don't get you. My point was to change the logic of the method you mentioned: def quote_bound_value(value, c = connection)
value = value.id_for_database if value.respond_to?(:id_for_database) # Add this
if value.respond_to?(:map) && !value.acts_like?(:string)
values = value.map { |v| v.respond_to?(:id_for_database) ? v.id_for_database : v }
if values.empty?
c.quote(c.cast_bound_value(nil))
else
values.map! { |v| c.quote(c.cast_bound_value(v)) }.join(",")
end
else
value = value.id_for_database if value.respond_to?(:id_for_database) # Remove this
c.quote(c.cast_bound_value(value))
end
end
I don't think a geometry could really be considered as acting like a string. You'd have to look into rails codebase for a more strict definition of what is expected by something that has the |
Sure you could move the The current Rails codebase only seems to use https://github.com/search?q=repo%3Arails%2Frails+acts_like%3F%28%3Astring%29&type=code There is no guarantee that it wouldn't be used in other places in future so I understand if you don't like this suggestion. Currently |
Oh got you, so it is the Regarding Could we come up with another solution? Maybe somewhere else in the backtrace, before calling |
Yes, sorry I should have told you my entrance point, it is sql = "ST_DWithin(geography(buildings.geom), geography(:geom), :buffer)"
Building.where(Building.sanitize_sql([ sql, geom: multi_geom, buffer: buffer ]) |
So maybe in between Here we'll go in |
I'd expect multi geoms to be bound / cast (?) as a multi geoms in active record:
To get a proper multi-geom I have to wrap it in an array
This is because AR checks if a method responds to
map
hereNot sure how best to solve this without some nasty monkey patch
The text was updated successfully, but these errors were encountered: