Finally, I found that so far the best solution is to use a dm-is-reflectiveplugin: https://github.com/godfat/dm-is-reflective .
It does not generate code for DataMapper models that reflects the existing database schema, but its methods for accessing properties are automatically available (if you continue to use this plugin, of course).
Here is a usage example:
require 'data_mapper'
require 'dm-is-reflective'
DataMapper.setup(:default, "postgres://user:pwd@localhost/db")
class Table
include DataMapper::Resource
is :reflective
reflect
end
DataMapper.finalize
entry = Table.first(nil, {:id => 469})
print entry.anotherField
source
share