This project is archived and is in readonly mode.

#6646 new
Philippe Creux

OrderedHash serialization does not work when storing arrays

Reported by Philippe Creux | March 29th, 2011 @ 11:21 PM

I'm storing an OrderedHash containing A/R validation errors in a serialized column. When I retreive it from the database the array of errors become a string containing the last item of the array.


class InvalidRecord < ActiveRecord::Base
  belongs_to :record, :polymorphic => true
  serialize :validation_errors


  create_table "invalid_records", :force => true do |t|
    t.integer  "record_id",         :null => false
    t.string   "record_type",       :null => false
    t.text     "validation_errors"
    t.datetime "created_at"
    t.datetime "updated_at"

The following code...

  r = => invalid_user, :validation_errors => invalid_user.errors)
  p r!
  p r


# new record: (errors on username is an array containing 2 items)
#<InvalidRecord id: nil, record_id: 1, record_type: "User", 
validation_errors: #<OrderedHash {:username=>["can't be blank", "is too short (minimum is 3 characters)"]}>, 
created_at: nil, updated_at: nil>

# saved record: (errors on username is now a string)
#<InvalidRecord id: 2, record_id: 1, record_type: "User", 
validation_errors: #<OrderedHash {:username=>"is too short (minimum is 3 characters)"}>, 
created_at: "2011-03-29 22:08:24", updated_at: "2011-03-29 22:08:26">

I'm using ree-1.8.7-2010.02 [ x86_64 ] with sqlite3.

Here is the YAML stored in the db:

--- !omap 
   - :username: can't be blank
   - :username: is too short (minimum is 3 characters)

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket