[英]Rails Polymorphic Associations without STI
This post describes my problem very well, but the answer to that post assumes that you use Single Table Inheritance (STI) for subclasses. 这篇文章很好地描述了我的问题,但是该文章的答案假设您对子类使用单表继承(STI)。 In my case the subclasses of SomeProf
has their own tables and since the _type
column is storing the class name of the superclass, this is not working. 在我的情况下, SomeProf
的子类具有自己的表,并且由于_type
列存储超类的类名,因此无法正常工作。 In my equivalent to SomeDeepProf1
I have declared that self.table_name = 'some_other_table'
and I would not like to use STI since the subclasses of my equivalent to SomeProf
have very different attributes. 在相当于SomeDeepProf1
我声明了self.table_name = 'some_other_table'
,但由于我与SomeProf
等效的子类具有非常不同的属性,因此我不希望使用STI。
Any suggestion of how to solve this? 关于如何解决这个问题的任何建议?
现在,我正在使用以下解决方法在SomeDeepProf1
类中解决此问题: before_create :set_poly_type_to_class_name ... def set_poly_type_to_class_name self.profile_type = self.profile.class.name end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.