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.
Model:
class InvalidRecord < ActiveRecord::Base
belongs_to :record, :polymorphic => true
serialize :validation_errors
end
Schema:
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"
end
The following code...
r = InvalidRecord.new(:record => invalid_user, :validation_errors => invalid_user.errors)
p r
r.save!
r.reload
p r
outputs:
# 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)