我目前正在开发一个基于现有数据库的新应用程序,使用 DataMapper 进行数据访问。但是,它在处理外键时的约定不是数据库使用的。
例子:
class Invoice
include DataMapper::Resource
storage_names[:default] = 'invoices'
property :id, Serial
# ... more properties ...
has n, :items
end
class Item
include DataMapper::Resource
storage_names[:default] = 'invoiceItems'
property :id, Serial
# ... more properties ...
belongs_to :invoice # this should use 'invoiceId' instead of 'invoice_id'
end
有什么办法可以让 DataMapper 使用的外键成为“invoiceId”而不是它目前尝试使用的“invoice_id”(如上面的评论所示)?我知道这可以通过添加普通字段来完成,:field => 'fieldName'
但我发现没有这样的关联方式。