拥有一个包含多个表的数据库。所有表具有相同的结构。我正在编写一个小型的Web应用程序来处理Ruby/Sinatra上的这个数据库。我想简化使用ORM的工作表 - Active Record或DataMapper(首选)。对于使用多个表的单一模式的手册提供的是这样的:ORM一个模型 - 乘法表
class Table
include DataMapper::Resource
property id, Serial
property item, String
end
class TableA < Table
self.table_name = 'table_a'
end
class TableB < Table
self.table_name = 'table_b'
end
这可怎么好十几张桌子来完成,而不copypaste?
如果可能,决定应该是添加/删除表而不更改代码/设置并重新启动应用程序的可能性。
喜欢的东西:
# Model declaration
DataMapper.finalize
itemA = Table.new (use_table: 'table_a')
itemB = Table.new (use_table: 'table_b')
http://stackoverflow.com/questions/5981724/multiple-database-tables-within-one-ar-model-in-rails-3 – Reisenfag