2010-07-15 45 views
0

我正在使用已经存在并由其他应用程序使用的数据库。DataMapper关联:如何指定包含关联行的表名?

设计数据库的人没有使用复数表名,所以DataMapper在跟随关联时选择错误的表名。

例如:

class Foo 
    has n :components # => the table name here should be COMPONENT, but datamapper uses COMPONENTS 
end 

如何改变这种行为?

回答

9

更改模型本身的名称。

class Component 
    # ... 
    storage_names[:default] = 'component' 
end 
+0

啊哈!谢谢。我是DataMapper的新手,所以我没有想到要这么做。 :) – 2010-07-16 20:03:55