Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a missing rollback when validation on an associated record fai…

…ls, and validate = first. Fixes #1147
  • Loading branch information...
commit b08aba8e861c161e1ed2e993355024ff4bc99c2b 1 parent 0761ede
@markstory markstory authored
View
6 cake/libs/model/model.php
@@ -1665,6 +1665,7 @@ function saveAll($data = null, $options = array()) {
}
}
}
+
if (!$this->__save($data, $options)) {
$validationErrors[$this->alias] = $this->validationErrors;
$validates = false;
@@ -1735,7 +1736,6 @@ function saveAll($data = null, $options = array()) {
case ($options['validate'] === 'first'):
$options['validate'] = true;
$return = array();
- continue;
break;
default:
if ($options['atomic']) {
@@ -1748,6 +1748,10 @@ function saveAll($data = null, $options = array()) {
return $return;
break;
}
+ if ($options['atomic'] && !$validates) {
+ $db->rollback($this);
+ return false;
+ }
}
}
View
40 cake/tests/cases/libs/model/model_write.test.php
@@ -3039,7 +3039,7 @@ function testSaveAllHasManyValidation() {
*
* @return void
*/
- function testSaveAllTransactionNoRollback() {
+ function testSaveAllManyRowsTransactionNoRollback() {
$this->loadFixtures('Post');
Mock::generate('DboSource', 'MockTransactionDboSource');
@@ -3063,6 +3063,44 @@ function testSaveAllTransactionNoRollback() {
}
/**
+ * test saveAll with transactions and ensure there is no missing rollback.
+ *
+ * @return void
+ */
+ function testSaveAllAssociatedTransactionNoRollback() {
+ $testDb = ConnectionManager::getDataSource('test_suite');
+
+ Mock::generate('DboSource', 'MockTransactionAssociatedDboSource');
+ $db = ConnectionManager::create('mock_transaction_assoc', array(
+ 'datasource' => 'MockTransactionAssociatedDbo',
+ ));
+ $db->columns = $testDb->columns;
+
+ $db->expectOnce('rollback');
+
+ $Post =& new Post();
+ $Post->useDbConfig = 'mock_transaction_assoc';
+ $Post->Author->useDbConfig = 'mock_transaction_assoc';
+
+ $Post->Author->validate = array(
+ 'user' => array('rule' => array('notEmpty'))
+ );
+
+ $data = array(
+ 'Post' => array(
+ 'title' => 'New post',
+ 'body' => 'Content',
+ 'published' => 'Y'
+ ),
+ 'Author' => array(
+ 'user' => '',
+ 'password' => "sekret"
+ )
+ );
+ $Post->saveAll($data);
+ }
+
+/**
* testSaveAllTransaction method
*
* @access public

0 comments on commit b08aba8

Please sign in to comment.
Something went wrong with that request. Please try again.