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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Apr 2008, at 12:08, Chirag wrote:> > 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? >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) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When I couldn''t find it in the documentation, I thought that it might be the case. Rails has strong opinion about certain things and if you try to work- around then it makes the life miserable. On Apr 3, 4:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 3 Apr 2008, at 12:08, Chirag wrote: > > > > > > > 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? > > 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) > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---