【发布时间】:2019-01-09 13:53:34
【问题描述】:
型号
class PushNotificationRequest < ApplicationRecord
serialize :details
移民
class CreateNotificationRequests < ActiveRecord::Migration[5.2]
def change
create_table :notification_requests do |t|
t.references :order, references: :spree_orders, index: false
t.string :key
t.json :details
t.string :type
t.timestamps
end
end
end
在控制台上创建数据
PushNotificationRequest.create(order: Spree::Order.last, details: {a: 2})
Mysql怪异存储
mysql> select * from notification_requests;
+----+----------+------+----------------+-------------------------+-----------+---------------------+---------------------+
| id | order_id | key | details | type | status | created_at | updated_at |
+----+----------+------+----------------+-------------------------+-----------+---------------------+---------------------+
| 7 | 19 | NULL | "---\n:a: 2\n" | PushNotificationRequest | INITIATED | 2019-01-09 13:45:40 | 2019-01-09 13:45:40 |
+----+----------+------+----------------+-------------------------+-----------+---------------------+---------------------+
details 列存储为一些奇怪的字符串,而不是正确的 json
我正在使用 mysql 8.0.12 和 rails 5.12
我有什么遗漏吗?
【问题讨论】:
标签: mysql ruby-on-rails json-serialization