Skip to content

Commit

Permalink
Fixed unique key constraints with multiple columns
Browse files Browse the repository at this point in the history
  • Loading branch information
juokaz committed Nov 17, 2010
1 parent 76e148a commit 91e15b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
Expand Up @@ -263,7 +263,7 @@ private function _appendUniqueConstraintDefinition($sql, Index $index)
$fields[] = $field . ' IS NOT NULL';
}

return $sql . ' WHERE ' . implode(' OR ', $fields);
return $sql . ' WHERE ' . implode(' AND ', $fields);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php
Expand Up @@ -24,7 +24,7 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo NVARCHAR(255) DEFAULT NULL, bar NVARCHAR(255) DEFAULT NULL)',
'CREATE UNIQUE INDEX test_foo_bar_uniq ON test (foo, bar)'
'CREATE UNIQUE INDEX test_foo_bar_uniq ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL'
);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public function getGenerateIndexSql()

public function getGenerateUniqueIndexSql()
{
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL';
}

public function getGenerateForeignKeySql()
Expand Down

0 comments on commit 91e15b7

Please sign in to comment.