鉴于从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