diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index 7bd0d5179..21ff4cade 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -703,8 +703,8 @@ class DboMssql extends DboSource { foreach ($indexes as $name => $value) { if ($name == 'PRIMARY') { - $out = 'PRIMARY KEY (' . $this->name($value['column']) . ')'; - } else { + $join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')'; + } else if (isset($value['unique']) && $value['unique']) { $out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE"; if (is_array($value['column'])) { @@ -713,8 +713,8 @@ class DboMssql extends DboSource { $value['column'] = $this->name($value['column']); } $out .= "({$value['column']});"; + $join[] = $out; } - $join[] = $out; } return $join; } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index 04ab3baed..87cd9f2da 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -519,6 +519,33 @@ class DboMssqlTest extends CakeTestCase { $expected = '[name] varchar(255) DEFAULT \'\''; $this->assertEqual($result, $expected); } +/** + * testBuildIndex method + * + * @return void + * @access public + */ + function testBuildIndex() { + $indexes = array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'client_id' => array('column' => 'client_id', 'unique' => 1) + ); + $result = $this->db->buildIndex($indexes, 'items'); + $expected = array( + 'PRIMARY KEY ([id])', + 'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);' + ); + $this->assertEqual($result, $expected); + + $indexes = array('client_id' => array('column' => 'client_id')); + $result = $this->db->buildIndex($indexes, 'items'); + $this->assertEqual($result, array()); + + $indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1)); + $result = $this->db->buildIndex($indexes, 'items'); + $expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);'); + $this->assertEqual($result, $expected); + } /** * testUpdateAllSyntax method * diff --git a/cake/tests/fixtures/aco_fixture.php b/cake/tests/fixtures/aco_fixture.php index 316925e81..5a8a1446d 100644 --- a/cake/tests/fixtures/aco_fixture.php +++ b/cake/tests/fixtures/aco_fixture.php @@ -47,7 +47,7 @@ class AcoFixture extends CakeTestFixture { var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'model' => array('type' => 'string', 'default' => ''), + 'model' => array('type' => 'string', 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'alias' => array('type' => 'string', 'default' => ''), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), diff --git a/cake/tests/fixtures/aco_two_fixture.php b/cake/tests/fixtures/aco_two_fixture.php index f139c9266..c5c3708a5 100644 --- a/cake/tests/fixtures/aco_two_fixture.php +++ b/cake/tests/fixtures/aco_two_fixture.php @@ -46,8 +46,8 @@ class AcoTwoFixture extends CakeTestFixture { */ var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), - 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true, 'default' => 0), - 'model' => array('type' => 'string', 'default' => ''), + 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), + 'model' => array('type' => 'string', 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'alias' => array('type' => 'string', 'default' => ''), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), diff --git a/cake/tests/fixtures/aro_fixture.php b/cake/tests/fixtures/aro_fixture.php index 96ae59828..26180de0e 100644 --- a/cake/tests/fixtures/aro_fixture.php +++ b/cake/tests/fixtures/aro_fixture.php @@ -47,7 +47,7 @@ class AroFixture extends CakeTestFixture { var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'model' => array('type' => 'string', 'default' => ''), + 'model' => array('type' => 'string', 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'alias' => array('type' => 'string', 'default' => ''), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), diff --git a/cake/tests/fixtures/aro_two_fixture.php b/cake/tests/fixtures/aro_two_fixture.php index a61d35c0b..8d2337bc5 100644 --- a/cake/tests/fixtures/aro_two_fixture.php +++ b/cake/tests/fixtures/aro_two_fixture.php @@ -47,7 +47,7 @@ class AroTwoFixture extends CakeTestFixture { var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'model' => array('type' => 'string', 'default' => ''), + 'model' => array('type' => 'string', 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'alias' => array('type' => 'string', 'default' => ''), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),