Browse Source

Account for null = false and null default value.

In this case we don't want to copy over the null as the null will not be
allowed by the schema.

Refs #5454
Mark Story 11 years ago
parent
commit
84e9edbbbf
2 changed files with 11 additions and 2 deletions
  1. 6 2
      src/Database/Schema/Table.php
  2. 5 0
      tests/TestCase/Database/Schema/TableTest.php

+ 6 - 2
src/Database/Schema/Table.php

@@ -342,9 +342,13 @@ class Table {
 	public function defaultValues() {
 		$defaults = [];
 		foreach ($this->_columns as $name => $data) {
-			if (array_key_exists('default', $data)) {
-				$defaults[$name] = $data['default'];
+			if (!array_key_exists('default', $data)) {
+				continue;
 			}
+			if ($data['default'] === null && $data['null'] !== true) {
+				continue;
+			}
+			$defaults[$name] = $data['default'];
 		}
 		return $defaults;
 	}

+ 5 - 0
tests/TestCase/Database/Schema/TableTest.php

@@ -162,8 +162,13 @@ class TableTest extends TestCase {
 		])->addColumn('title', [
 			'type' => 'string',
 			'default' => 'A title'
+		])->addColumn('name', [
+			'type' => 'string',
+			'null' => false,
+			'default' => null,
 		])->addColumn('body', [
 			'type' => 'text',
+			'null' => true,
 			'default' => null,
 		]);
 		$result = $table->defaultValues();