【发布时间】:2021-12-16 23:30:12
【问题描述】:
我有数据存储在这样的数据库中
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
accepted: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
number_of_order: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
condition: between_number
value: 0&5
removed: !ruby/hash:ActiveSupport::HashWithIndifferentAccess {}
但我必须在 laravel 中这样显示
{"accepted"=>{"last_order_total"=>{"condition"=>"between_number", "value"=>"1000&2000"}, "last_order_date"=>{"condition"=>"before", "value"=>"2021-10-01T00:00:00.000Z"}, "number_of_order"=>{"condition"=>"between_number", "value"=>"10&20"}}, "removed"=>{"last_order_date"=>{"condition"=>"after", "value"=>"2021-10-14T00:00:00.000Z"}, "last_order_total"=>{"condition"=>"between_number", "value"=>"1200&1500"}}}
那么如何转换这样的数据库值呢?我正在使用 Postgresql 来存储数据。
【问题讨论】:
-
这是一种非常奇怪的将数据存储在数据库中的方式...
-
能否删除字符串中对
!ruby/hash:ActiveSupport::HashWithIndifferentAccess的所有引用,然后将其解析为常规YAML? -
您好,@TomLord 不,我无法删除引用,因为它已在其他应用程序中使用。
-
我的意思是获取后删除。第一步:从数据库中读取数据。第二步:删除引用。第 3 步:解析 YAML。第 4 步:显示它。
-
我不建议您更新数据库中的任何内容。
标签: ruby laravel postgresql