這幾乎在Difference Between find and Where with Relationships中回答,但不完全相同。 (請注意,我是如何巧妙地改變了問題的標題!) 我做的查詢「where」和「find」之間的區別
a = Libation.where("user_id = 1") # gets 10 records
b = a.sum("count * weight") # Get right answer
c = Libation.where("user_id = 2") # gets 8 records
d = c.sum("count * weight") # Get right answer
現在我做
e = Libation.all # gets 18 records, good
f = e.sum("count * weight") # BOOM! I get
NoMethodError (undefined method `+' for #<Libation:0x3b91e88>):
堅果。我試圖找到相關的文檔,但發現很少。或者我不在正確的位置。
謝謝,非常好的解釋。關於時間我讀了範圍。 – rtfminc 2011-05-20 06:39:47