Commit 6c6cb3cd by Qiang Xue

Fixes #853: Added composite FK support for SQLite.

parent 02fd82c4
...@@ -126,7 +126,13 @@ class Schema extends \yii\db\Schema ...@@ -126,7 +126,13 @@ class Schema extends \yii\db\Schema
$sql = "PRAGMA foreign_key_list(" . $this->quoteSimpleTableName($table->name) . ')'; $sql = "PRAGMA foreign_key_list(" . $this->quoteSimpleTableName($table->name) . ')';
$keys = $this->db->createCommand($sql)->queryAll(); $keys = $this->db->createCommand($sql)->queryAll();
foreach ($keys as $key) { foreach ($keys as $key) {
$table->foreignKeys[] = array($key['table'], $key['from'] => $key['to']); $id = (int)$key['id'];
if (!isset($table->foreignKeys[$id])) {
$table->foreignKeys[$id] = array($key['table'], $key['from'] => $key['to']);
} else {
// composite FK
$table->foreignKeys[$id][$key['from']] = $key['to'];
}
} }
} }
......
...@@ -6,9 +6,4 @@ use yiiunit\framework\db\SchemaTest; ...@@ -6,9 +6,4 @@ use yiiunit\framework\db\SchemaTest;
class SqliteSchemaTest extends SchemaTest class SqliteSchemaTest extends SchemaTest
{ {
protected $driverName = 'sqlite'; protected $driverName = 'sqlite';
public function testCompositeFk()
{
$this->markTestSkipped('sqlite does not allow getting enough information about composite FK.');
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment