This post很好地描述了我的问题,但该帖子的答案假定您对子类使用单表继承(STI)。在我的例子中,SomeProf
的子类有自己的表,因为_type
列存储了超类的类名,所以这不起作用。在我相当于SomeDeepProf1
的情况下,我已声明self.table_name = 'some_other_table'
并且我不想使用STI,因为我的等同于SomeProf
的子类具有非常不同的属性。
有关如何解决这个问题的任何建议吗?
答案 0 :(得分:0)
现在我正在使用以下解决方法在SomeDeepProf1
类中解决此问题:
before_create :set_poly_type_to_class_name
...
def set_poly_type_to_class_name
self.profile_type = self.profile.class.name
end