I have been struggling for quite sometime with this.
Is there any way to configure the Model to store user defined value in
the inheritance_column instead of the default value (which is
class_name)
The problem I have is like this:
I have a User model and there are different models which inherit from
this like Admin, Premium, Professional, etc.
Each of these inherited models are identified by a field named role_id
in the users table and it contains integer values for e.g. 1 for
Admin, 2 for Premium, 3 for Professional and so on.
I want to set this role_id field as the inheritance_column, which can
be easily done by specifying :inheritance_column => “role_id” in the
User Model. But how do I configure Rails to store these numerical
values in the role_id field, instead of the Class name?
I will really appreciate if anybody can help me out with this.
this like Admin, Premium, Professional, etc.
Each of these inherited models are identified by a field named role_id
in the users table and it contains integer values for e.g. 1 for
Admin, 2 for Premium, 3 for Professional and so on.
I want to set this role_id field as the inheritance_column, which can
be easily done by specifying :inheritance_column => “role_id” in the
User Model. But how do I configure Rails to store these numerical
values in the role_id field, instead of the Class name?
Well you could overwrite those fields yourself, but then bad things
would happen when you loaded one of those objects because Rails would
try to create an instance of 1 instead of an instance of Admin. I
don’t believe there’s any support for this in rails (not to say that
it couldn’t be done but you would have to change rails itself)