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

  • Home
  • SEARCH
  • 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 952783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:56:58+00:00 2026-05-15T23:56:58+00:00

I have a db column which is a serialized Hash : class Foo <

  • 0

I have a db column which is a serialized Hash:

class Foo < ActiveRecord::Base
   serialize :bar
end

When I store a hash inside of bar that is a few levels deep, the deeper levels do not seem to properly deserialize when I need them. Objects one level deep get deserialzed just fine. However, objects 2 or more levels deep remain YAML classes.

I tried manually deserializing using YAML::load() but got an error saying the argument wasn’t an instance of IO.

Does anyone know why the complete Ruby object doesn’t deserialize?

EDIT: After further investigation, the problem seems to stem from the fact that I’m calling a virtual attribute from the serialized YAML.

class Foo < ActiveRecord::Base
   serialize :bar
end

class Bar < ActiveRecord::Base
    attr_accessor :enabled
end

@bars = @foo.bar[:bars]
@bars.each do |bar|
   puts bar.enabled
end

yields:

NoMethodError: undefined method `enabled' for #<YAML::Object:0xb6f11844>
    from (irb):12
    from (irb):11:in `each'
    from (irb):11
    from :0

Does this mean deserialization isn’t “real”, ie, the YAML object acts similar to the original object, but it’s not an actual instance of that object?

  • 1 1 Answer
  • 1 View
  • 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-05-15T23:56:58+00:00Added an answer on May 15, 2026 at 11:56 pm

    There’s two things to keep in mind when serializing user-defined objects instead of “plain old Ruby” objects.

    • You need to have the user-defined classes loaded before the object can be properly de-serialized or the instances will be of a generic YAML::Object type. De-serializing does not auto-load classes.
    • Some objects may not properly serialize without some customization, though this is generally not the case.

    Generally serializing instances of an ActiveRecord::Base object is a bad idea as these have an extraordinary amount of baggage that will need to be encoded in addition to your attribute. It is best to build a class that is derived directly from Object, which is the default behavior, or from a simple base class of some sort.

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You may want to browse the Oracle concept guide, especially… May 16, 2026 at 11:06 am
  • Editorial Team
    Editorial Team added an answer Here's a JavaScript function you can use to calculate the… May 16, 2026 at 11:06 am
  • Editorial Team
    Editorial Team added an answer At the API level, for the reason you mentioned: you're… May 16, 2026 at 11:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have an entity which is constructed from a string and can be serialized
I have the folowing code to fetch a record and update one column which
I have 2 tables- master and detail table. Master Table has ID column which
I have a column in my database table which has lows of text and
I have a melted dataset containing a column value which represent an absolute number
I have a column named Sysdate in several tables, which is causing SQL errors
In my stored procedure I have to pass a table and column name which
I want to create user-specific validations. User has a column called rule_values which is
The Query Optimizer is estimating that the results of a join will have only
I have a certain POJO which needs to be persisted on a database, current

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.