I have a geocoordinate class that gives models some useful methods for working with geocoordinates. It includes "geocoordinates =", which takes an array.
https://gist.github.com/mboyle/58dd3add830bbdeef316
You can call the "geocoordinates" to get the coordinates in the array:
irb(main):056:0> b.geocoordinates
=> [-118.25, 34.197]
When I assign these coordinates:
irb(main):058:0> b.geocoordinates = [34.197, -118.25]
(1.8ms)
UPDATE users
SET geocoordinates = 'SRID=4326;POINT(' || 34.197 || ' ' || -118.25 || ')'
WHERE id = 347708
(0.7ms)
UPDATE activities
SET geocoordinates = users.geocoordinates
FROM users
WHERE activities.user_id = users.id
AND users.id = 347708
AND NOT postgis.ST_Equals(activities.geocoordinates, users.geocoordinates)
=> [34.197, -118.25]
Everything seems to add up and exit correctly. However, if I query the model again and then read the geo-coordinates, lat / long will be canceled:
irb(main):059:0> b = User.find(b.id)
irb(main):060:0> b.geocoordinates
(0.7ms)
SELECT postgis.ST_Y(geocoordinates) AS latitude, postgis.ST_X(geocoordinates) AS longitude
FROM users
WHERE id = 347708
=> [-118.25, 34.197]
I canβt understand in my life why this is happening. Somebody knows?
source
share