I have a rails class that serializes one attribute.
class Statistic < ActiveRecord::Base
serialize :userlist
end
When a statistic object is loaded and it’s userlist changed from a
String to an Array userlist always gets serialized back into a String.
Objects that are properly deserialized into Arrays stay that way. The
framework seems to remember and deserialize :userlist into a String
even if it went in as an Array.
The goal of this exercise is to convert all String userlists to Array.
If I change the class (serialize :userlist, Array) before converting I
get TypeMismatch exceptions.
ActiveRecord::SerializationTypeMismatch: userlist was supposed to
be a Array, but was a String
Is there a way to force AR to interpret userlist as an Array?
Found the problem. The String is not correct YAML:
YAML::load(s.userlist)
ArgumentError: syntax error:ScannerException while scanning a quoted
scalar we had this found unexpected end of stream from (irb):8
This occurred to me too. The column type is text. I don’t recall the
length, but it was between 50,000 & 100,000 characters. I’ll check
the max_allowed_packet setting when I get back to work.
This occurred to me too. The column type is text. I don’t recall the
length, but it was between 50,000 & 100,000 characters. I’ll check
the max_allowed_packet setting when I get back to work.
Text columns have a 65535 limit (mediumtext and longtext columns can
take much more)
Fred
Thanks. That is the problem. 65535 characters on the nose.
This occurred to me too. The column type is text. I don’t recall the
length, but it was between 50,000 & 100,000 characters. I’ll check
the max_allowed_packet setting when I get back to work.
Text columns have a 65535 limit (mediumtext and longtext columns can
take much more)
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.