Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ ActiveRecord::Base#destroy! #6629

Merged
merged 1 commit into from Jun 6, 2012
Merged

+ ActiveRecord::Base#destroy! #6629

merged 1 commit into from Jun 6, 2012

Conversation

marcandre
Copy link
Contributor

save! and variants are super useful when we have some generic exception handler setup, for example with rescue_from, and we expect the operation to succeed.

destroy actions would benefit the same way of a destroy! version in the same way (especially since they so often succeed).

Doesn't it sound great too? destroy!

# and <tt>destroy!</tt> raises ActiveRecord::RecordNotSaved. See
# ActiveRecord::Callbacks for further details.
def destroy!
destroy or raise ActiveRecord::RecordNotDestroyed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ||? It is in Rails Code Guidelines to not use and and or. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

@marcandre
Copy link
Contributor Author

BTW, the commit also supplements the rdoc for destroy, mentioning callbacks and return value of false.

@carlosantoniodasilva
Copy link
Member

Great, can we have a changelog entry as well please?

@marcandre
Copy link
Contributor Author

Changelog entry added.

#
# There's a series of callbacks associated with <tt>destroy!</tt>. If
# the <tt>before_destroy</tt> callback return +false+ the action is cancelled
# and <tt>destroy!</tt> raises ActiveRecord::RecordNotSaved. See

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, just noticed the constant name is wrong here, should be ActiveRecord::RecordNotDestroyed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the pitfalls of copy-paste :-)
Fixed, thanks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe :), thanks.

carlosantoniodasilva added a commit that referenced this pull request Jun 6, 2012
Add ActiveRecord::Base#destroy!
@carlosantoniodasilva carlosantoniodasilva merged commit e638c61 into rails:master Jun 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants