Browse Source

Not validating created and modified fields in baked tables, fixes #3464

Jose Lorenzo Rodriguez 12 years ago
parent
commit
cee14ac7ef

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

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

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

@@ -423,13 +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],
 		];
 		$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]
+		];
+		$this->assertEquals($expected, $result);
 	}
 
 /**