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'在這裏比較好。 –