As a cleaner alternative to Single Table Inheritance, we talked about implementing "Class Table Inheritance":http://martinfowler.com/eaaCatalog/classTableInheritance.html in DM.
As an added benefit, this would make it very easy to do Model Translation à la "Globalize":http://www.globalize-rails.org/globalize/. To really facilitate switching languages, we discussed adding a context block that would allow DM to automatically choose a sub-class of a given parent class based on the supplied context (e.g. locale).
Ruby
database(:default, 'en-US') do
products = Product.all
products.first.name # => Meatballs
end
database(:default, 'es-ES') do
products = Product.all
products.first.name # => Albóndigas
end
Created by Josh H - 2007-11-10 20:37:30 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/53
该提问来源于开源项目:datamapper/dm-core