Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fde0b0

Browse filesBrowse files
committed
merged branch jaugustin/fix-propel-modelChoiceList (PR #8505)
This PR was merged into the 2.2 branch. Discussion ---------- [bridge] [propel1] [ModelChoiceList] fix issue #8499 call getPrimaryKey on a non object | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8499 | License | MIT | Doc PR | no This fix an issue #8499 introduced by the PR #8223 CC @willdurand @havvg Commits ------- 2ebb783 fix issue #8499 modelChoiceList call getPrimaryKey on a non object
2 parents ddebe06 + 2ebb783 commit 5fde0b0
Copy full SHA for 5fde0b0

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed

‎src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function getIndicesForChoices(array $models)
289289
$choices = $this->fixChoices($models);
290290
foreach ($this->getChoices() as $i => $choice) {
291291
foreach ($choices as $j => $givenChoice) {
292-
if ($this->getIdentifierValues($choice) === $this->getIdentifierValues($givenChoice)) {
292+
if (null !== $givenChoice && $this->getIdentifierValues($choice) === $this->getIdentifierValues($givenChoice)) {
293293
$indices[] = $i;
294294
unset($choices[$j]);
295295

@@ -416,6 +416,10 @@ private function getIdentifierValues($model)
416416
return array($model->getPrimaryKey());
417417
}
418418

419+
if (null === $model) {
420+
return array();
421+
}
422+
419423
return $model->getPrimaryKeys();
420424
}
421425

‎src/Symfony/Bridge/Propel1/Tests/Form/ChoiceList/ModelChoiceListTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/Tests/Form/ChoiceList/ModelChoiceListTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,16 @@ public function testDifferentEqualObjectsAreChoosen()
199199

200200
$this->assertEquals(array(1), $choiceList->getIndicesForChoices(array($choosenItem)));
201201
}
202+
203+
public function testGetIndicesForNullChoices()
204+
{
205+
$item = new Item(1, 'Foo');
206+
$choiceList = new ModelChoiceList(
207+
self::ITEM_CLASS,
208+
'value',
209+
array($item)
210+
);
211+
212+
$this->assertEquals(array(), $choiceList->getIndicesForChoices(array(null)));
213+
}
202214
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.