目前,在嵌入文档时,我得到了一系列哈希(这是我的模型:)
class Category
include Mongoid::Document
field :name, type: String
field :user_id, type: Integer
field :url, type: String
field :category_id, type: Integer
field :enabled, type: Boolean
belongs_to :user
embeds_many :subcategory, store_as: 'subcategories'
...
end
class Subcategory
include Mongoid::Document
field :subcategory_name, type: String
field :category_id, type: Integer
field :subcategory_id, type: Integer
field :enabled, type: Boolean
embeds_many :product, store_as: 'products'
embedded_in :category
...
end
有没有办法可以将它存储为哈希?像:
{
...
"subcategory": {
"subcat_1_id": {...},
"subcat_2_id": {...},
...
},
...
},
无需在应用程序上进行数据操作(类似于我不知道的Mongoid选项?)
提前致谢!