Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50694f2

Browse files
committed
minor #48342 [Form] Call getChoicesForValues() once, to prevent several SQL queries (elementaire)
This PR was merged into the 6.3 branch. Discussion ---------- [Form] Call `getChoicesForValues()` once, to prevent several SQL queries | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The feature "Keeping valid submitted choices when additional choices are submitted" adds some overload to list the valid choices. With options set to `multiple=true`, `expanded=false` and using an `EntityType`, it performs several queries, one for each value. Commits ------- d5f11e0 [Form] Call getChoicesForValues() once, to prevent several SQL queries
2 parents 9ef729e + d5f11e0 commit 50694f2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
144144
}
145145
}
146146
} else {
147-
foreach ($data as $value) {
148-
if ($choiceList->getChoicesForValues([$value])) {
149-
$knownValues[] = $value;
150-
unset($unknownValues[$value]);
151-
}
147+
foreach ($choiceList->getChoicesForValues($data) as $index => $choice) {
148+
$value = $data[$index];
149+
$knownValues[] = $value;
150+
unset($unknownValues[$value]);
152151
}
153152
}
154153

0 commit comments

Comments
 (0)