Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for correctly converting a SqliteSchema containing com…

…piste primary

keys
  • Loading branch information...
commit 282a64847df15a84857c7e37ff81659bd3a04bf8 1 parent 9db2d00
@lorenzo lorenzo authored
View
8 Cake/Database/Schema/SqliteSchema.php
@@ -129,10 +129,12 @@ public function convertFieldDescription(Table $table, $row) {
}
$table->addColumn($row['name'], $field);
if ($row['pk'] == true) {
- $table->addConstraint('primary', [
+ $constraint = (array)$table->constraint('primary') + [
'type' => Table::CONSTRAINT_PRIMARY,
- 'columns' => [$row['name']]
- ]);
+ 'columns' => []
+ ];
+ $constraint['columns'] = array_merge($constraint['columns'], [$row['name']]);
+ $table->addConstraint('primary', $constraint);
}
}
View
31 Test/TestCase/Database/Schema/SqliteSchemaTest.php
@@ -155,6 +155,37 @@ public function testConvertColumn($type, $expected) {
}
/**
+ * Tests converting multiple rows into a primary constraint with multiple
+ * columns
+ *
+ * @return void
+ */
+ public function testCovenrtCompositPrimaryKey() {
+ $driver = $this->getMock('Cake\Database\Driver\Sqlite');
+ $dialect = new SqliteSchema($driver);
+
+ $field1 = [
+ 'pk' => true,
+ 'name' => 'field1',
+ 'type' => 'INTEGER(11)',
+ 'notnull' => false,
+ 'dflt_value' => 0,
+ ];
+ $field2 = [
+ 'pk' => true,
+ 'name' => 'field2',
+ 'type' => 'INTEGER(11)',
+ 'notnull' => false,
+ 'dflt_value' => 1,
+ ];
+
+ $table = new \Cake\Database\Schema\Table('table');
+ $dialect->convertFieldDescription($table, $field1);
+ $dialect->convertFieldDescription($table, $field2);
+ $this->assertEquals(['field1', 'field2'], $table->primaryKey());
+ }
+
+/**
* Creates tables for testing listTables/describe()
*
* @param Connection $connection
Please sign in to comment.
Something went wrong with that request. Please try again.