我有这个对象:
class MessageSetting
include Mongoid::Document
include Mongoid::Timestamps::Created
#relationships
embedded_in :user
field :when_new_order, :type => Boolean, :default => "true"
field :when_cancel_order, :type => Boolean, :default => "true"
field :when_expire_order, :type => Boolean, :default => "true"
field :when_reject_order, :type => Boolean, :default => "true"
field :when_accept_order, :type => Boolean, :default => "true"
field :when_in_progress_overtime, :type => Boolean, :default => "true"
field :when_is_canceled_due_overtime, :type => Boolean, :default => "true"
field :when_deliver_order, :type => Boolean, :default => "true"
field :when_order_complete, :type => Boolean, :default => "true"
field :when_open_dispute, :type => Boolean, :default => "true"
field :when_buyer_request_refund, :type => Boolean, :default => "true"
field :when_seller_made_refund, :type => Boolean, :default => "true"
field :when_seller_made_dispute_response, :type => Boolean, :default => "true"
field :when_buyer_made_dispute_response, :type => Boolean, :default => "true"
attr_accessible :when_new_order, :when_cancel_order, :when_expire_order, :when_reject_order,
:when_accept_order, :when_in_progress_overtime, :when_is_canceled_due_overtime,
:when_deliver_order, :when_deliver_order, :when_order_complete, :when_open_dispute,
:when_buyer_request_refund, :when_seller_made_refund, :when_seller_made_dispute_response, :when_buyer_made_dispute_response
def active_new_order?
when_new_order?
end
def active_when_cancel_order?
when_cancel_order?
end
def active_when_expire_order?
when_expire_order?
end
def active_when_reject_order?
when_reject_order?
end
def active_when_accept_order?
when_accept_order?
end
def active_when_in_progress_overtime?
when_in_progress_overtime?
end
def active_when_is_canceled_due_overtime?
when_is_canceled_due_overtime?
end
def active_when_deliver_order?
when_deliver_order?
end
def active_when_order_complete?
when_order_complete?
end
def active_when_open_dispute?
when_open_dispute?
end
def active_when_buyer_request_refund?
when_buyer_request_refund?
end
def active_when_seller_made_refund?
when_seller_made_refund?
end
def active_when_seller_made_dispute_response?
when_seller_made_dispute_response?
end
def active_when_buyer_made_dispute_response?
when_buyer_made_dispute_response?
end
end
我知道我可以使用 mongoid进行“序列化” :
field :status_message_setting, type: Hash
那么我可以:
m = MessageSetting.new
m.status_message_setting = {:when_new_order => true, :when_cancel_order => false, ...}
m.save
我需要知道关于性能、最佳实践和可用资源的信息,最好用hash
这个模型“序列化”?