fix issue #8499 modelChoiceList call getPrimaryKey on a non object

This commit is contained in:
Jérémie Augustin 2013-07-17 09:33:13 +02:00
parent ddebe064db
commit 2ebb783c05
2 changed files with 17 additions and 1 deletions

View File

@ -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();
}

View File

@ -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)));
}
}