@@ -17,15 +17,15 @@ objects from the database.
17
17
| | - `em `_ |
18
18
| | - `query_builder `_ |
19
19
+-------------+------------------------------------------------------------------+
20
- | Overridden | - `choices `_ |
21
- | options | - `data_class `_ |
20
+ | Overridden | - `choice_name `_ |
21
+ | options | - `choice_value `_ |
22
+ | | - `choices `_ |
23
+ | | - `data_class `_ |
22
24
+-------------+------------------------------------------------------------------+
23
25
| Inherited | from the :doc: `choice </reference/forms/types/choice >` type: |
24
26
| options | |
25
27
| | - `choice_attr `_ |
26
- | | - `choice_name `_ |
27
28
| | - `choice_translation_domain `_ |
28
- | | - `choice_value `_ |
29
29
| | - `expanded `_ |
30
30
| | - `group_by `_ |
31
31
| | - `multiple `_ |
@@ -124,7 +124,7 @@ choice_label
124
124
The ``choice_label `` option was introduced in Symfony 2.7. Prior to Symfony
125
125
2.7, it was called ``property `` (which has the same functionality).
126
126
127
- **type **: ``string `` or ``callable ``
127
+ **type **: ``string ``, ``callable `` or :class: ` Symfony \\ Component \\ PropertyAccess \\ PropertyPath `
128
128
129
129
This is the property that should be used for displaying the entities as text in
130
130
the HTML element::
@@ -194,6 +194,40 @@ return a ``QueryBuilder``.
194
194
Overridden Options
195
195
------------------
196
196
197
+ choice_name
198
+ ~~~~~~~~~~~
199
+
200
+ .. versionadded :: 2.7
201
+ The ``choice_name `` option was introduced in Symfony 2.7.
202
+
203
+ **type **: ``string ``, ``callable `` or :class: `Symfony\\ Component\\ PropertyAccess\\ PropertyPath ` **default **: id
204
+
205
+ By default the name of each field is the id of the entity, if it can be read
206
+ from the class metadata by an internal id reader. Otherwise the process will
207
+ fall back to using increasing integers.
208
+
209
+ choice_value
210
+ ~~~~~~~~~~~~
211
+
212
+ .. versionadded :: 2.7
213
+ The ``choice_value `` option was introduced in Symfony 2.7.
214
+
215
+ **type **: ``string ``, ``callable `` or :class: `Symfony\\ Component\\ PropertyAccess\\ PropertyPath ` **default **: id
216
+
217
+ As for the ``choice_name `` option, ``choice_value `` uses the id by default.
218
+ It allows an optimization in the :class: ``Symfony\\ Bridge\\ Doctrine\\ Form\\ ChoiceList\\ Loader\\ DoctrineChoiceLoader` ` which will
219
+ only load the ids passed as values while the form submission.
220
+ It prevents all non submitted entities to be loaded from the database, even
221
+ when defining the ``query_builder `` option.
222
+ If it may be useful to set this option using an entity's property as string
223
+ value (e.g for some API), you will gain performances by letting this option set
224
+ by default.
225
+
226
+ .. note ::
227
+
228
+ If the id cannot be read, for BC, the component checks if the class implements
229
+ ``__toString() `` and will use an incremental integer otherwise.
230
+
197
231
choices
198
232
~~~~~~~
199
233
@@ -219,12 +253,8 @@ type:
219
253
220
254
.. include :: /reference/forms/types/options/choice_attr.rst.inc
221
255
222
- .. include :: /reference/forms/types/options/choice_name.rst.inc
223
-
224
256
.. include :: /reference/forms/types/options/choice_translation_domain.rst.inc
225
257
226
- .. include :: /reference/forms/types/options/choice_value.rst.inc
227
-
228
258
.. include :: /reference/forms/types/options/expanded.rst.inc
229
259
230
260
.. include :: /reference/forms/types/options/group_by.rst.inc
0 commit comments