From 6c6cb3cd90b19a23ad202fcefc9617bfb5e59a76 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 13 Sep 2013 20:41:40 -0400 Subject: [PATCH] Fixes #853: Added composite FK support for SQLite. --- framework/yii/db/sqlite/Schema.php | 8 +++++++- tests/unit/framework/db/sqlite/SqliteSchemaTest.php | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/framework/yii/db/sqlite/Schema.php b/framework/yii/db/sqlite/Schema.php index d4fb245..bca26c1 100644 --- a/framework/yii/db/sqlite/Schema.php +++ b/framework/yii/db/sqlite/Schema.php @@ -126,7 +126,13 @@ class Schema extends \yii\db\Schema $sql = "PRAGMA foreign_key_list(" . $this->quoteSimpleTableName($table->name) . ')'; $keys = $this->db->createCommand($sql)->queryAll(); 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']; + } } } diff --git a/tests/unit/framework/db/sqlite/SqliteSchemaTest.php b/tests/unit/framework/db/sqlite/SqliteSchemaTest.php index 9b17a1d..f3f6b60 100644 --- a/tests/unit/framework/db/sqlite/SqliteSchemaTest.php +++ b/tests/unit/framework/db/sqlite/SqliteSchemaTest.php @@ -6,9 +6,4 @@ use yiiunit\framework\db\SchemaTest; class SqliteSchemaTest extends SchemaTest { protected $driverName = 'sqlite'; - - public function testCompositeFk() - { - $this->markTestSkipped('sqlite does not allow getting enough information about composite FK.'); - } }