Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:11:33+00:00 2026-06-18T04:11:33+00:00

I have this object: class MessageSetting include Mongoid::Document include Mongoid::Timestamps::Created #relationships embedded_in :user field

  • 0

I have this object:

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

I know that I can make “serialize” with mongoid with:

field :status_message_setting, type: Hash

then I can:

m = MessageSetting.new
m.status_message_setting = {:when_new_order => true, :when_cancel_order => false, ...}
m.save

I need to know referring to performance, best practices and resources available, it is better to “serialize” with a hash this model?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:11:34+00:00Added an answer on June 18, 2026 at 4:11 am

    Not all Ruby classes can be serialized out of the box, but lucky for you, Hashes are one of the classes that can be. Therefore there is no reason to write your own serialization for them. But if you do and there is an increase in speed, it will be minimal. Serialization is used primarily for persisting fields with custom datatypes.

    It wouldn’t speed up your database, but if you really wanted to save space, you could create a custom type for an all-boolean hash and serialize your hash into bitcode. You would create the custom class and define a mongoize instance method, and mongoize,demongoize, and evolve class methods according to how you want to serialize the data. Yes, this is definatly possible. In practice however, it’s a hassle to implement and wouldn’t save you that much space unless your hashes are huge compared to the rest of the data in the model.

    For your situation, a much easier way to save space would be to shorten all your field names like this:

    field :wno, as: :when_new_order, :type => Boolean, :default => "true"
    field :wco, as: :when_cancel_order, :type => Boolean, :default => "true" ...
    

    Since the field name is repeated in the database for every document that is stored, long field names will begin to take up a lot of extra space. Since you pass an alias, e.g. :when_new_order, then your model will act exactly like it did before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, i have this object for exemple: public class User { public int Id
I have this object: public class Profile { public int Id {get;set;} public List<User>
Let's say I have this object: [JsonObject] public class User { [JsonProperty(PropertyName = id)]
I have this object: class a { public string Application; public DateTime From, To;
Assume I have this domain object... public class SpansMultipleTables { public int CommonID {get;
I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
have written this little class, which generates a UUID every time an object of
So I have a class like this: class Encoder(object): movie = None def __init__(self,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.