From: Alex Young Date: 2006-06-28T22:03:18+09:00 Subject: Re: How to model Hibernate multi-table inheritance with ActiveRecord? Marcus Andersson wrote: > Hi > > I have this "old" database mainly modeled for Hibernate. The java model > has something called Asset. Asset is inherited by SomeAsset and > AnotherAsset and the similar stuff is in the asset table and the > specific data for SomeAsset is in table some_asset and for AnotherAsset > in another_asset. This is then reflected in hibernate using a > element. > > What would be the best way to model this in ActiveRecord? I cannot > change the exisiting database structure beyond adding new columns (ie I > cannot move values from the join tables back to the main table and use > STI). > > Could I implement method_missing in Asset to just delegate to methods > that might exist in SomeAsset or AnotherAsset? I only use duck typing so > from a type perspective it would be fine. This would make it hard to > override behaviour from Asset in subclasses though (since they aren't > subclasses...). > > Is there another better solution? I'd have SomeAsset and AnotherAsset instances each hold a delegate Asset object that they proxy any calls they can't answer themselves to. I've played around a little with trying to implement a full class table inheritance scheme for AR on that basis, but never really had enough need for it myself to polish it up. -- Alex