This project is archived and is in readonly mode.
ActiveRecord::Base#exists? returns true when called with nil
-
Franco Catena
I think that in this case ActiveRecord interpret this question like
dept.employees.count > 0
So in a way the question "exists?" is translates to "at least one (without conditions) exists?"The behaviour you whant can be achieved with
dept.employees.exists?(:id => nil)
And in this case the question "exists?" is translates to "at least one (without id) exists?" -
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low
I think Franco is right here. In fact the default argument for id is
nil— https://github.com/rails/rails/blob/master/activerecord/lib/active_... hence it works exactly as Franco has explained. I'm closing the ticket but if you still feel there is a discrepancy leave a comment and I'll reopen.