0
我有模特这样导轨 - Mongoid查询在关联领域
class TestOne
field value
belongs_to test_two ,:class_name => 'TestTwo'
end
class TestTwo
field name
field start_time, :type => DateTime
has_many TestOne
end
I am running a query of range like this
result = TestOne.where(:value => "some_value" , 'test_two.start_time' => (Time.now-1.days..Time.now + 1.days).last
的结果集上面的查询是空的,即使存在着TestOne多家唱片是符合标准。任何人都可以提出我可能做错了什么。
使用'pluck(:id)'而不是'.only(:id).map(&:id)' –
@ CyrilDuchon-Doris你是对的,'pluck'在这里比较好。 –