嵌入式文档的哈希单线程哈希哈希值

时间:2014-08-20 11:42:07

标签: mongodb ruby-on-rails-4 mongoid

目前,在嵌入文档时,我得到了一系列哈希(这是我的模型:)

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选项?)

提前致谢!

0 个答案:

没有答案