Andrew Kaspick
2011-Aug-10 21:51 UTC
Difference in exists? method behaviour between 2.x and 3.x
Sent this to the wrong list before, so here are the two emails I had initially sent... Email I sent yesterday... =============== The following is how "exists?" works between Rails 2.x and 3.x Rails 2.x>> User.exists?=> true>> User.exists?(nil)=> false>> Store.first.users.exists?=> true>> Store.first.users.exists?(nil)=> false Rails 3.x>> User.exists?=> true>> User.exists?(nil)=> true>> Store.first.users.exists?=> true>> Store.first.users.exists?(nil)=> true Rails 3.x always returns true, but I don''t believe this should be the case and it should work as it was in rails 2.x. Is there a reason for the difference in Rails 3.x? Passing nil should not return true IMO... it doesn''t make sense to do so. I can submit a patch if the behaviour in Rails 3.x is deemed incorrect. Regards, Andrew And my followup today.... =============== Patch provided at https://github.com/rails/rails/pull/2485 Fixes cases where a params id may be nil; exists? should not return true in this case. params[:id] => nil Topic.exists?(params[:id]) => false # should be false always, never true Please +1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.