Skip to content
This repository
Browse code

comp mod for saveAll()

better approach

test case to assert saveAll still behaves like previous versions
  • Loading branch information...
commit 1e2ac0b9c8f8b00e322242bb24dca9e546d59fba 1 parent 2e15689
Mark authored October 11, 2012
2  lib/Cake/Model/Model.php
@@ -2017,7 +2017,7 @@ protected function _prepareUpdateFields($data) {
2017 2017
  * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array
2018 2018
  * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array
2019 2019
  */
2020  
-	public function saveAll($data, $options = array()) {
  2020
+	public function saveAll($data = array(), $options = array()) {
2021 2021
 		$options = array_merge(array('validate' => 'first'), $options);
2022 2022
 		if (Hash::numeric(array_keys($data))) {
2023 2023
 			if ($options['validate'] === 'only') {
28  lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -4726,6 +4726,32 @@ public function testSaveAllHasManyValidationOnly() {
4726 4726
 	}
4727 4727
 
4728 4728
 /**
  4729
+ * test that saveAll still behaves like previous versions (does not necessarily need a first argument)
  4730
+ *
  4731
+ * @return void
  4732
+ */
  4733
+	public function testSaveAllWithSet() {
  4734
+		$this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag');
  4735
+		$data = array(
  4736
+			'Article' => array(
  4737
+				'user_id' => 1,
  4738
+				'title' => 'Article Has and belongs to Many Tags'
  4739
+			),
  4740
+			'Tag' => array(
  4741
+				'Tag' => array(1, 2)
  4742
+			),
  4743
+			'Comment' => array(
  4744
+				array(
  4745
+					'comment' => 'Article comment',
  4746
+					'user_id' => 1
  4747
+		)));
  4748
+		$Article = new Article();
  4749
+		$Article->set($data);
  4750
+		$result = $Article->saveAll();
  4751
+		$this->assertFalse(empty($result));
  4752
+	}
  4753
+
  4754
+/**
4729 4755
  * test that saveAll behaves like plain save() when supplied empty data
4730 4756
  *
4731 4757
  * @link http://cakephp.lighthouseapp.com/projects/42648/tickets/277-test-saveall-with-validation-returns-incorrect-boolean-when-saving-empty-data
@@ -4740,7 +4766,7 @@ public function testSaveAllEmptyData() {
4740 4766
 		$this->assertFalse(empty($result));
4741 4767
 
4742 4768
 		$model = new ProductUpdateAll();
4743  
-		$result = $model->saveAll(array());
  4769
+		$result = $model->saveAll();
4744 4770
 		$this->assertFalse($result);
4745 4771
 	}
4746 4772
 

0 notes on commit 1e2ac0b

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