模型
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
有什么我想念的吗?