class A
include DataMapper::Resource
def self.default_repository_name
:alt_db
end
property :aid, Integer, :key => true
# other stuff
belongs_to :b, :model => 'B', :child_key => [ :bid ]
end
class B
include DataMapper::Resource
# this one is in the default repo
property :bid, Integer, :key => true
# other stuff
belongs_to :c, :model => 'C', :child_key => [ :cid ]
end
class C
include DataMapper::Resource
# this one is in the default repo
property :cid, Integer, :key => true
# other stuff
end
如果我只有A和B,这可以正常工作。如果我加C,但是,我得到一个错误:跨不同存储库链接数据映射关系
DM-核心/模型/ property.rb:73:在`新':错误的参数数目(4 3)(引发ArgumentError)
如果我想与DataMapper建立一系列关系,这样我就可以在一个地方给出一个ID,并通过一系列对后续表的主键ID字段的引用来获得一张数据,比如说,有四张表。我这样做?
编辑:挖掘到从堆栈跟踪的DM来源:
DataMapper.repository(other_repository_name) do
properties << klass.new(self, name, options, type)
end
这也正是引发错误。事实上,在这种情况下,klass是DataMapper Integer属性,它的初始化方法只接受三个选项(模型,名称和选项散列)。
这整个块只执行,因为我使用多个存储库,虽然B和C在同一个存储库,所以我不知道这是否揭示了为什么它在cid属性上出现错误。
EDIT2:
我已经尝试了所有的排列,看来,当你链接,一旦你跨越数据库边界,即必须是链的末端。例如,由于A是:alt_db,B是:默认值,所以B的深度就像我可以走的一样深,不管C是:default,:alt_db还是第三个选项。
如果相反,A和B都是:默认的,或者两者都是:alt_db,然后C是相反的,C会尽可能深。
虽然我不明白这种行为。
这很奇怪...我有相同的版本,它不工作.... – hsiu 2011-04-21 14:09:53