This project is archived and is in readonly mode.
ActiveRecord::Base exists? expects argument
Reported by Tobi | January 29th, 2009 @ 10:50 AM | in 2.x
Tiny but annoying bug if you want to have beautiful code:
The Bug By now ActiveRecord::Base method "exists?" expects an argument.
Example: to check if at least one entry exists in table 'persons':
Person.exists?
But this doesn't work, as an argument is expected. Even more common scenario happens with named scope:
Person.rails_developer.exists?
The Workaround As a workaround passing an empty hash works, but looks ugly:
Person.exists?({})
The Fix So my proposal to get back to beautiful code: Add empty hash as default parameter to 'extists?' method:
def exists?(id_or_conditions = {} )
...
end
Cheers Tobi
Comments and changes to this ticket
-
Tobi February 1st, 2009 @ 02:14 PM
- Tag changed from argument, default, exists, missing to argument, default, exists, missing, patch
cheers!
-
Repository February 5th, 2009 @ 07:51 PM
- State changed from new to committed
(from [5a8f764661bcdf9c6ce503c0ff343a1970deb1bb]) Add ActiveRecord::Base.exists? with no args [#1817 state:committed]
Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1817 ActiveRecord::Base exists? expects argument (from [5a8f764661bcdf9c6ce503c0ff343a1970deb1bb]) Add Act...