我已经通过覆盖==运算符来解决这个问题,但是它让我疯了,我无法找到解释。据我所知,ActiveRecord应该通过id字段确定两个现有记录的相等性,对吗?
显然,不!
Loading development environment (Rails 3.0.4)
irb(main):001:0> c = ChallengeClaim.find(1)
=> #<ChallengeClaim id: 1, collection_id: 954, creation_id: nil, creation_type: nil, request_signup_id: 2, request_prompt_id: 5, claiming_user_id: 8, sent_at: nil, fulfilled_at: nil, defaulted_at: nil, created_at: "2011-09-23 04:39:07", updated_at: "2011-09-23 04:39:07">
irb(main):002:0> c2 = ChallengeClaim.find(2)
=> #<ChallengeClaim id: 2, collection_id: 954, creation_id: nil, creation_type: nil, request_signup_id: 2, request_prompt_id: 4, claiming_user_id: 8, sent_at: nil, fulfilled_at: nil, defaulted_at: nil, created_at: "2011-11-07 17:47:33", updated_at: "2011-11-07 17:47:33">
irb(main):003:0> c == c2
=> true
?!?!! ??!
任何解释都表示感谢,所以我可以再次入睡。产品:&gt;
答案 0 :(得分:0)
正如Chris Heald在评论中指出的那样,实际上比较运算符&lt; =&gt;是在ChallengeClaim上定义的!