Changing the instantiated table when using STI


#1

Is there any way to get AR to instantiate a different class when using
STI? Where it would normally instantiate Digit, I would like it to
instantiate SkelDigit. Here’s why…

My rails app has the following STI hierarchy:

Digit < Glyph < ActiveRecord::Base

My migrate script can’t use those classes directly however (backward
compatibility issues), so I created some skeleton classes:

 SkelDigit < SkelGlyph < ActiveRecord::Base

This way, my migrate script can use the skelton classes to move the
data.

The problem is, the type field of the glyphs table contains “Digit”,
“Letter” etc. Therefore, when I call SkelDigit.find(:all), I receive an
array of Digit objects, not SkelDigit objects. Then, of course,
everything breaks.

Is there any way I can tell AR to instantiate a SkelDigit instead of a
Digit? It looks like AR::Base::instantiate has something to do with
this but it’s a private routine and poorly documented.

Thank you very much,

- Scott