Marcus Andersson
2006-Jun-27 21:33 UTC
[Rails] How to model Hibernate multi-table inheritance with ActiveRecord?
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 <joined-subclass/> 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. Would I crash Rails in some way? Is there another better solution? Best Regards, Marcus