鑑於從ActiveRecord
命名爲Foo
s的集合,爲什麼Array#include?
似乎沒有調用Foo.==
但index
呢?Array :: include?在ActiveRecord集合不調用op ==?
class Foo < ActiveRecord::Base
def ==(s)
self.name == s
end
end
class Bar < ActiveRecord::Base
has_many :foos
end
bar.foos << Foo.new(:name => 'hmm')
bar.foos.all.include?('hmm') # does select all from db every time
=> true
bar.foos.include?('hmm') # does not go to db, but does not find the Foo!
=> false
bar.foos.index('hmm') # does not go to db, but does find the Foo[0] !
=> 0
bar.foos.index('eh') # no such object
=> nil
我理解淺薄有關代理,但(沒有繞道進入AR源)爲什麼指數表現看似正確,但包括哪些內容?不是 !?
這是代理行爲中的錯誤,還是/此行爲記錄在某處?
謝謝。
會員?作品。爲什麼不包括? – tribalvibes 2010-03-12 06:38:04