rgeo/activerecord-postgis-adapter

Occasional geometry fields being treated as strings

waissbluth opened this issue · 2 comments

I sometimes get a geometry object treated as a string in situations like User.select('*, ST_Centroid(polygon) as centroid).first.centroid.x

The error is:

NoMethodError - undefined method `x' for "0101000020E610000072E115E915EC55C0900DCCE87AF44440":String:`

When running a SELECT that generates on-the-fly geometry fields, e.g. SELECT users.*, ST_Centroid(polygon) as centroid FROM users and then call user.centroid.x.

This typically will only happen in development resolve itself restarting the server solves it, making it very hard to debug or fix.

I don't know if this kind of query is supposed to be supported -- but it is very helpful to run things like these. I suspect that the model may need some additional nudging towards the spatial type of this dynamic field, or a factory setup.

Any help with this would be appreciated. Thanks.

We've run into something similar but having been able to try it down yet.

@waissbluth this should fix it: #309