开发者

DataMapper Nested conditions: count issue

Here is the models:

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

Inserting some data:

f = Foo.create
b1 = Bar.create
b2 = Bar.create
b3 = Bar.create
f.bars = [b1, b2, b3]
f.save

So, now I have one foo, three bars, and the foo has all the bars. Everything is fine.

Now I want to request some foos having bar#1 and bar#3:

Foo.all(Foo.bars.id => [1,3])
=> [#<Foo @id=1>] #ok
Foo.all(Foo.bars.id => [1,3]).count
=> 2 #why?

And here is the question: why array length is 1 and collection count is 2? How can I get both 1? I'd like to stick to the request with the nested conditions. Is it a bug or a misuse?

DM 1.1.开发者_C百科0


Unfortunately you've hit a bug. I just reported an issue with your example attached: https://github.com/datamapper/dm-aggregates/issues/3


I think you should be able to get correct result by doing this for now:

Foo.count(Foo.bars.id => [1,3])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜