Rails 5,使用数组作为列/属性问题的sqlite3

问题描述 投票:1回答:2

这是我在Rails 5模型中使用数组的方式在迁移中

  t.text :diagnoses, array: true, default: []

在模型中

class Patient < ApplicationRecord
  serialize :diagnoses, Array
end

在我的种子方法中,我正在这样做

  patient = Patient.create(first_name: 'John', last_name: 'Smith', admission: a)
  patient.diagnoses = [1, 2]
  patient.save!

它给出错误为

ActiveRecord::SerializationTypeMismatch: can't dump `diagnoses`: was supposed to be a Array, but was a Integer. -- 0

感谢您的帮助!

ruby-on-rails sqlite serialization ruby-on-rails-5
2个回答
0
投票

前一段时间,我遇到了这个确切的问题。我发现以下解决方法:


0
投票

我会认真考虑实际上实际上是正确使用关系数据库。

© www.soinside.com 2019 - 2024. All rights reserved.