views:

27

answers:

2

Hi All,

I want to know, what is a rails way of converting a subclass record to another subclass record, just changing type isn't working and also superclass to subclass and vice versa.

Thanks in advance

Markiv

+1  A: 

All you should have to do is change the type field. Make sure you save the record, and reload the Ruby object from the database.

If that doesn't work, can you provide some Ruby code that isolates the problem?

Michael Melanson
thanx that worked
markiv
A: 

Are you asking how to change an object that is a subclass to different subclass of it's superclass? This isn't really possible in the OO scheme of things. It's possible to cast an object from a superclass to a subclass, but you can't cast it back, since the object may now contains variables and methods that the superclass does not.

lambdabutz
According to the title of this post, the OP is using Single Table Inheritance.
Michael Melanson
You're right, it is possible, although you still might pull stuff that doesn't make sense, but it shouldn't break your object. I'm interested in the use case for this, would either of you mind elaborating on what you needed to do to change the type column?
lambdabutz