-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add docs for saveOrFail and deleteOrFail #4722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1106,6 +1106,36 @@ receiving from the end user is the correct type. Failing to correctly handle | |
| complex data could result in malicious users being able to store data they | ||
| would not normally be able to. | ||
|
|
||
| Strict Saving | ||
| ============= | ||
|
|
||
| .. php:method:: saveOrFail($entity, $options = []) | ||
|
|
||
|
|
||
| Using this method will throw an :php:exc:`Cake\\ORM\\Exception\\PersistenceFailedException` | ||
| if the application rules checks failed, the entity contains errors or the save was aborted by a callback. | ||
| Using this can be helpful when you performing complex database operations without human monitoring, | ||
| for example, inside a Shell task. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add:
etc?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could use it there if they catch the exception.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah but not without catching it then :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Do not use' is pretty strongly worded when it can be used if you catch the resulting exceptions. |
||
|
|
||
| .. warning:: | ||
|
|
||
| Do not use this method when the save was triggered by a user, for example, | ||
| within a controller action or if you want to give a user feedback within a form. | ||
|
|
||
| If you want to track down the entity that failed to save, you can use the | ||
| :php:meth:`Cake\\ORM\Exception\\PersistenceFailedException::getEntity()` method:: | ||
|
|
||
| try { | ||
| $table->saveOrFail($entity); | ||
| } catch (\Cake\ORM\Exception\PersistenceFailedException $e) { | ||
| echo $e->getEntity(); | ||
| } | ||
|
|
||
| As this internally perfoms a :php:meth:`Cake\\ORM\\Table::save()` call, all corresponding save events | ||
| will be triggered. | ||
|
|
||
| .. versionadded:: 3.4.1 | ||
|
|
||
| Saving Multiple Entities | ||
| ======================== | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/perfoms/performs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix that post-merge.