ruby-on-rails - Rails PostGIS ActiveRecord 适配器有时返回字符串而不是 RGeo::Geos::CAPIPointImpl 对象
问题描述
我PostGIS ActiveRecord Adapter
在 Rails API 应用程序中使用。我有一个名为的数据库表events
,其中一列是 PostGIS 几何列,coordinates
例如:
create_table 'events' do |t|
t.geometry 'coordinates;
end
当用户查询我的 API 时,我使用Netflix's Fast JSON API
序列化我的响应:
class EventSerializer
include FastJsonapi::ObjectSerializer
attribute :coordinates do |object|
# coincidentally my column name and PostGIS Adapters method for getting the coordinates is the same
object.coordinates.coordinates
end
end
现在大部分时间上述工作,我得到一个有坐标的响应,但时不时我会收到以下错误:
'undefined method coordinates for "0101000020E610000061C3D32B65965DC03657CD7344F64040" String, did you mean codepoints'
上述情况偶尔发生,我无法重新创建它,因为大多数情况下一切正常。很好,我的意思是我在数据库中只有 5 条记录,如果执行最终序列化 5 条记录的相同函数,它将工作 50 次,但随后 1 次它会给我上面的错误并继续给我上面的错误后续调用。然后我重新启动服务器,一切恢复正常。
我最好的猜测是,序列化程序处理对象的速度比适配器解析 RGeo 对象以返回坐标的速度要快,但我不知道如何解决这个问题。
任何人有任何解决方案?
解决方案
推荐阅读
- haskell - 导入作为 Haskell 中的运算符的类型族
- bixby - 具有多列的输入视图
- logstash - TCP入口点的Nginx-Ingress不起作用
- c - 在 C 中使用 setenv()
- android - React Native + Expo 获取缓存控制
- kubernetes - 在 Kubernetes 下调度任务失败
- javascript - 网络抓取功能返回“未定义”,但在我使用 console.log 时有效
- python - 带有quandl的url NotFoundError
- mysql - mysql group by Select group 为一列的不同行选择值
- apache-spark - 找不到翻译