擁有一個包含多個表的數據庫。所有表具有相同的結構。我正在編寫一個小型的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