gpt4 book ai didi

ruby-on-rails - Rails 4.2.5 在 SerializationTypeMismatch 之后将值重新分配给序列化字段

转载 作者:数据小太阳 更新时间:2023-10-29 08:11:35 24 4
gpt4 key购买 nike

我有一个序列化专栏

class TestSerialize < ActiveRecord::Base
serialize :parameters, Array
end

当我尝试分配字符串时

a = TestSerialize.new
a.parameters = "inappropriate type"

如我所愿

ActiveRecord::SerializationTypeMismatch:Attribute was supposed to be a Array, but was a String. -- "inappropriate type".

但是当我尝试重新分配“parameters”字段时,我仍然遇到与之前分配的值相同的错误

a.parameters = []
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Array, but was a String. -- "inappropriate type"

这是预期的行为吗?

2.2.3 :003 > a = TestSerialize.new
=> #<TestSerialize id: nil, parameters: [], first_name: {}, last_name: "", created_at: nil, updated_at: nil>
2.2.3 :004 > a.parameters
=> []
2.2.3 :005 > a.parameters = "test"
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Array, but was a String. -- "test"

2.2.3 :006 > a
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Array, but was a String. -- "test"

2.2.3 :007 > a.parameters
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Array, but was a String. -- "test"

2.2.3 :008 > a.first_name
=> {}

2.2.3 :009 > reload!
Reloading...
=> true
2.2.3 :010 > a
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Array, but was a String. -- "test"

最佳答案

从 Rails 团队得到答案 https://github.com/rails/rails/issues/23449

关于ruby-on-rails - Rails 4.2.5 在 SerializationTypeMismatch 之后将值重新分配给序列化字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com