Reworked Table::$_primaryKey

parent 971b9b48
......@@ -112,6 +112,7 @@ Table columns are no longer indexed by column name. Use the `name` attribute of
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance.
- Method `Doctrine\DBAL\Schema\Comparator::diffTable()` now optionally returns null instead of false.
- Property `Doctrine\DBAL\Schema\Table::$_primaryKeyName` is now optionally null instead of false.
- Property `Doctrine\DBAL\Schema\TableDiff::$newName` is now optionally null instead of false.
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::tablesExist()` no longer accepts a string. Use `Doctrine\DBAL\Schema\AbstractSchemaManager::tableExists()` instead.
- Method `Doctrine\DBAL\Schema\OracleSchemaManager::createDatabase()` no longer accepts `null` for `$database` argument.
......
......@@ -41,8 +41,8 @@ class Table extends AbstractAsset
/** @var Index[] */
protected $_indexes = [];
/** @var string */
protected $_primaryKeyName = false;
/** @var string|null */
protected $_primaryKeyName;
/** @var UniqueConstraint[] */
protected $_uniqueConstraints = [];
......@@ -163,8 +163,12 @@ class Table extends AbstractAsset
*/
public function dropPrimaryKey() : void
{
if ($this->_primaryKeyName === null) {
return;
}
$this->dropIndex($this->_primaryKeyName);
$this->_primaryKeyName = false;
$this->_primaryKeyName = null;
}
/**
......@@ -500,9 +504,11 @@ class Table extends AbstractAsset
*/
public function getPrimaryKey() : ?Index
{
return $this->hasPrimaryKey()
? $this->getIndex($this->_primaryKeyName)
: null;
if ($this->_primaryKeyName !== null) {
return $this->getIndex($this->_primaryKeyName);
}
return null;
}
/**
......@@ -528,7 +534,7 @@ class Table extends AbstractAsset
*/
public function hasPrimaryKey() : bool
{
return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName);
return $this->_primaryKeyName !== null && $this->hasIndex($this->_primaryKeyName);
}
/**
......@@ -684,7 +690,7 @@ class Table extends AbstractAsset
}
if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) ||
($this->_primaryKeyName !== false && $indexCandidate->isPrimary())
($this->_primaryKeyName !== null && $indexCandidate->isPrimary())
) {
throw IndexAlreadyExists::new($indexName, $this->_name);
}
......
......@@ -12,7 +12,6 @@ parameters:
# changing these would be a BC break, to be done in next major
- '~^Method Doctrine\\DBAL\\Query\\QueryBuilder::execute\(\) should return Doctrine\\DBAL\\Driver\\Statement\|int but returns Doctrine\\DBAL\\Driver\\ResultStatement\.\z~'
- '~^Property Doctrine\\DBAL\\Schema\\Table::\$_primaryKeyName \(string\) does not accept (default value of type )?false\.\z~'
# https://bugs.php.net/bug.php?id=78126
- '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~'
......
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