Fix problem when 1 column identifier in propel is a string.
The ModelChoiceList thinks it can be used as the index of the ChoiceList, when it can only be used if it is an integer.
This commit is contained in:
parent
50a62da114
commit
972e503fa8
@ -45,6 +45,13 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
*/
|
*/
|
||||||
private $loaded = false;
|
private $loaded = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use the identifier for index generation
|
||||||
|
*
|
||||||
|
* @var Boolean
|
||||||
|
*/
|
||||||
|
private $identifierAsIndex = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $labelPath
|
* @param string $labelPath
|
||||||
@ -69,6 +76,13 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
$choices = array();
|
$choices = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (1 === count($this->identifier)) {
|
||||||
|
// TODO this should be current($this->identifier)->isInteger() when propel ColumnMap contains the isInteger function
|
||||||
|
if ($this->isInteger(current($this->identifier))) {
|
||||||
|
$this->identifierAsIndex = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($choices, $labelPath, array(), $groupPath);
|
parent::__construct($choices, $labelPath, array(), $groupPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +238,7 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
// know that the IDs are used as indices
|
// know that the IDs are used as indices
|
||||||
|
|
||||||
// Attention: This optimization does not check choices for existence
|
// Attention: This optimization does not check choices for existence
|
||||||
if (1 === count($this->identifier)) {
|
if ($this->identifierAsIndex) {
|
||||||
$indices = array();
|
$indices = array();
|
||||||
|
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
@ -259,7 +273,7 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
// know that the IDs are used as indices and values
|
// know that the IDs are used as indices and values
|
||||||
|
|
||||||
// Attention: This optimization does not check values for existence
|
// Attention: This optimization does not check values for existence
|
||||||
if (1 === count($this->identifier)) {
|
if ($this->identifierAsIndex) {
|
||||||
return $this->fixIndices($values);
|
return $this->fixIndices($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +297,7 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
*/
|
*/
|
||||||
protected function createIndex($model)
|
protected function createIndex($model)
|
||||||
{
|
{
|
||||||
if (1 === count($this->identifier)) {
|
if ($this->identifierAsIndex) {
|
||||||
return current($this->getIdentifierValues($model));
|
return current($this->getIdentifierValues($model));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,4 +365,15 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
|
|
||||||
return $model->getPrimaryKeys();
|
return $model->getPrimaryKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this column in an integer
|
||||||
|
* TODO we could add this function to propel ColumnMap class instead
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function isInteger($col)
|
||||||
|
{
|
||||||
|
return $col->getType() === \PDO::PARAM_INT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user