2012-05-09 110 views

回答

1

最后,我发现到现在最好的解决办法是使用dm-is-reflective plugin: https://github.com/godfat/dm-is-reflective

它不会产生DataMapper的模式反映了现有的数据库模式的代码,但它的属性访问方法是自动可用(只要您继续使用这个插件,当然)。

下面是使用的例子:你的回答

require 'data_mapper' 
require 'dm-is-reflective' 

DataMapper.setup(:default, "postgres://user:[email protected]/db") 

class Table 
    include DataMapper::Resource 

    is :reflective #activate dm-is-reflective 

    reflect #reflects eeach property. You can be more specific (look at plugin documentation) 
end 

DataMapper.finalize 

#Even if no field is defined, all of them are accessible 
entry = Table.first(nil, {:id => 469}) 
print entry.anotherField 
2

尝试检查https://github.com/yogo/dm-reflection或其任何叉..

+0

感谢@TomMeinIschmidt。我已经更新了答案,指出现在是官方存储库的Yogo fork。但我没有尝试过它的好运气。 “dm-reflection”已经死了。在余吴库有一个应该用'DataMapper的工作分支1.0'但至少我没有工作。它的安装没有工作,但我解决了,但仍然没有工作。我认为它有一些错误的依赖关系。我发现了另一个我现在发布的解决方案。 –

相关问题