fix issue #8499 modelChoiceList call getPrimaryKey on a non object
This commit is contained in:
parent
ddebe064db
commit
2ebb783c05
|
@ -289,7 +289,7 @@ class ModelChoiceList extends ObjectChoiceList
|
|||
$choices = $this->fixChoices($models);
|
||||
foreach ($this->getChoices() as $i => $choice) {
|
||||
foreach ($choices as $j => $givenChoice) {
|
||||
if ($this->getIdentifierValues($choice) === $this->getIdentifierValues($givenChoice)) {
|
||||
if (null !== $givenChoice && $this->getIdentifierValues($choice) === $this->getIdentifierValues($givenChoice)) {
|
||||
$indices[] = $i;
|
||||
unset($choices[$j]);
|
||||
|
||||
|
@ -416,6 +416,10 @@ class ModelChoiceList extends ObjectChoiceList
|
|||
return array($model->getPrimaryKey());
|
||||
}
|
||||
|
||||
if (null === $model) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $model->getPrimaryKeys();
|
||||
}
|
||||
|
||||
|
|
|
@ -199,4 +199,16 @@ class ModelChoiceListTest extends Propel1TestCase
|
|||
|
||||
$this->assertEquals(array(1), $choiceList->getIndicesForChoices(array($choosenItem)));
|
||||
}
|
||||
|
||||
public function testGetIndicesForNullChoices()
|
||||
{
|
||||
$item = new Item(1, 'Foo');
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array($item)
|
||||
);
|
||||
|
||||
$this->assertEquals(array(), $choiceList->getIndicesForChoices(array(null)));
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue