Can someone explain me this behaviour of AR object:
u = User.first
uu = u.dup
uu == u #=> true
u == uu #=> false
Why is the latter not true?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is because
ActiveRecord::Base#==returnsfalseif the second object is a new record. Sinceuu.new_record?istrue, when doingu == uuit returnsfalse; butu.new_record?isfalse, souu == udoes not fail that check.This behavior has changed since Rails 3.0 and both
u == uuanduu == uwill returnfalsein Rails 3.2 (and possibly 3.1).