我有一个Rails模型,它有一个类型为"json"的数据库列:
create_table "games", force: true do |t|
t.json "game_board"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
太棒了现在我该如何使用它?它真的像treating the field like a Hash
一样简单吗?
self.game_board[:player1] = 1
self.game_board[:cards] = cards.to_hash
如果我写这篇文章,一切都会像预期的那样工作吗?所以在future 的客户端API调用中,我可以做到这一点:
self.game_board[:player] # And get back the 1 that I put here before
那么性能呢?即使从未读取该字段,是否每次都会对整个game_board
进行反序列化?每次我更改"哈希"的一部分时,是否会重新写入该字段(在数据库写入时)