【发布时间】:2020-02-17 11:07:23
【问题描述】:
我的应用程序中有一个类似于这样的自定义字段的多态关系:
class CustomFieldValue < ApplicationRecord
belongs_to :custom_field_type
belongs_to :custom_field_valuable, polymorphic: true
end
class CustomFieldType < ApplicationRecord
has_many :custom_field_values
end
custom_field_type 表基本上包含有关字段类型(选择、复选框等)的一些详细信息,以及自定义字段所属模型的“model_type”列。
custom_field_value 表具有预期的多态列“custom_field_valuable_type”和“custom_field_valuable_id”,它们工作正常,但看到 custom_field_value 属于已经存储了 model_type 的 custom_field_type,我想知道是否有一种方法可以取消 custom_field_valuable_type ?
我已经尝试用
重新定义“custom_field_valuable_type”def custom_field_valuabkle_type
self.custom_field_type.model_type
end
但这不起作用,因为没有要查询的列。
【问题讨论】:
标签: ruby-on-rails activerecord