强制rails来读取属性而不是关联

时间:2018-03-15 13:44:29

标签: ruby-on-rails ruby-on-rails-4 activerecord serialization associations

我有点奇怪的问题。我试图重构一些代码,目前我的模型设置为:

class Level < ActiveRecord::Base
  serialize :states, Array
end

在上面,序列化数组state存储不同状态的id。

我想将其转移到join table,其中包含LevelState的ID,因此我更新了模型,如下所示:

class Level < ActiveRecord::Base
  has_many :levels_states, inverse_of: :level
  has_many :states, through: :levels_states
  serialize :states, Array
end

现在的问题是我无法从列states传输现有数据,因为Rails正在寻找关联states而不是序列化数组。我想创建一个迁移来传输SQL数据,但我无法访问states数组。

0 个答案:

没有答案