This project is archived and is in readonly mode.

#1817 ✓committed
Tobi

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

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

Referenced by

Pages