Browse Source

Merge pull request #4863 from cakephp/fixture-no-pk

Always return an array from Table::primaryKey().
Mark Story 11 years ago
parent
commit
92e79f293f
2 changed files with 9 additions and 3 deletions
  1. 3 3
      src/Database/Schema/Table.php
  2. 6 0
      tests/TestCase/Database/Schema/TableTest.php

+ 3 - 3
src/Database/Schema/Table.php

@@ -419,8 +419,8 @@ class Table {
 /**
  * Get the column(s) used for the primary key.
  *
- * @return array|null Column name(s) for the primary key.
- *   Null will be returned if a table has no primary key.
+ * @return array Column name(s) for the primary key. An
+ *   empty list will be returned when the table has no primary key.
  */
 	public function primaryKey() {
 		foreach ($this->_constraints as $name => $data) {
@@ -428,7 +428,7 @@ class Table {
 				return $data['columns'];
 			}
 		}
-		return null;
+		return [];
 	}
 
 /**

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

@@ -318,6 +318,12 @@ class TableTest extends TestCase {
 				'columns' => ['id']
 			]);
 		$this->assertEquals(['id'], $table->primaryKey());
+
+		$table = new Table('articles');
+		$table->addColumn('id', 'integer')
+			->addColumn('title', 'string')
+			->addColumn('author_id', 'integer');
+		$this->assertEquals([], $table->primaryKey());
 	}
 
 /**