這裏是機型:DataMapper的嵌套條件:計數問題
class Foo
include DataMapper::Resource
property :id, Serial
has n, :foo_bars
has n, :bars, :through => :foo_bars
end
class Bar
include DataMapper::Resource
property :id, Serial
has n, :foo_bars
has n, :foos, :through => :foo_bars
end
class FooBar
include DataMapper::Resource
belongs_to :foo, :key => true
belongs_to :bar, :key => true
end
插入一些數據:
f = Foo.create
b1 = Bar.create
b2 = Bar.create
b3 = Bar.create
f.bars = [b1, b2, b3]
f.save
所以,現在我有一個foo
,三個bar
S和foo
擁有所有bar
s。一切安好。
現在我想請一些foo
小號爲bar
#1和#bar
3:
Foo.all(Foo.bars.id => [1,3])
=> [#<Foo @id=1>] #ok
Foo.all(Foo.bars.id => [1,3]).count
=> 2 #why?
這裏是問題:爲什麼數組的長度爲1,集合數爲2?我怎樣才能得到1?我想堅持嵌套條件的請求。這是一個錯誤還是濫用?
DM 1.1.0