Browse Source

Merge pull request #3465 from cakephp/3.0-validate-timestamps-fix

3.0 validate timestamps fix
Mark Story 12 years ago
parent
commit
bda0f73311

+ 2 - 2
src/Console/Command/Task/ModelTask.php

@@ -412,8 +412,8 @@ class ModelTask extends BakeTask {
  * @return array Array of validation for the field.
  */
 	public function fieldValidation($fieldName, array $metaData, $primaryKey) {
-		$ignoreFields = array_merge($primaryKey, ['created', 'modified', 'updated']);
-		if ($metaData['null'] === true && in_array($fieldName, $ignoreFields)) {
+		$ignoreFields = ['created', 'modified', 'updated'];
+		if (in_array($fieldName, $ignoreFields)) {
 			return false;
 		}
 

+ 12 - 1
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -423,11 +423,22 @@ class ModelTaskTest extends TestCase {
 		$model = TableRegistry::get('BakeArticles');
 		$result = $this->Task->getValidation($model);
 		$expected = [
-			'id' => ['rule' => 'numeric', 'allowEmpty' => 'create'],
 			'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => false],
 			'title' => ['rule' => false, 'allowEmpty' => false],
 			'body' => ['rule' => false, 'allowEmpty' => true],
 			'published' => ['rule' => 'boolean', 'allowEmpty' => true],
+			'id' => ['rule' => 'numeric', 'allowEmpty' => 'create']
+		];
+		$this->assertEquals($expected, $result);
+
+		$model = TableRegistry::get('BakeComments');
+		$result = $this->Task->getValidation($model);
+		$expected = [
+			'bake_article_id' => ['rule' => 'numeric', 'allowEmpty' => false],
+			'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => false],
+			'comment' => ['rule' => false, 'allowEmpty' => true],
+			'published' => ['rule' => false, 'allowEmpty' => true],
+			'otherid' => ['rule' => 'numeric', 'allowEmpty' => 'create']
 		];
 		$this->assertEquals($expected, $result);
 	}