@@ -17,15 +17,15 @@ objects from the database.
1717| | - `em `_ |
1818| | - `query_builder `_ |
1919+-------------+------------------------------------------------------------------+
20- | Overridden | - `choices `_ |
21- | options | - `data_class `_ |
20+ | Overridden | - `choice_name `_ |
21+ | options | - `choice_value `_ |
22+ | | - `choices `_ |
23+ | | - `data_class `_ |
2224+-------------+------------------------------------------------------------------+
2325| Inherited | from the :doc: `choice </reference/forms/types/choice >` type: |
2426| options | |
2527| | - `choice_attr `_ |
26- | | - `choice_name `_ |
2728| | - `choice_translation_domain `_ |
28- | | - `choice_value `_ |
2929| | - `expanded `_ |
3030| | - `group_by `_ |
3131| | - `multiple `_ |
@@ -115,7 +115,7 @@ choice_label
115115 The ``choice_label `` option was introduced in Symfony 2.7. Prior to Symfony
116116 2.7, it was called ``property `` (which has the same functionality).
117117
118- **type **: ``string `` or ``callable ``
118+ **type **: ``string ``, ``callable `` or :class: ` Symfony \\ Component \\ PropertyAccess \\ PropertyPath `
119119
120120This is the property that should be used for displaying the entities as text in
121121the HTML element::
@@ -183,6 +183,40 @@ the entity and return an instance of ``QueryBuilder``.
183183Overridden Options
184184------------------
185185
186+ choice_name
187+ ~~~~~~~~~~~
188+
189+ .. versionadded :: 2.7
190+ The ``choice_name `` option was introduced in Symfony 2.7.
191+
192+ **type **: ``string ``, ``callable `` or :class: `Symfony\\ Component\\ PropertyAccess\\ PropertyPath ` **default **: id
193+
194+ By default the name of each field is the id of the entity, if it can be read
195+ from the class metadata by an internal id reader. Otherwise the process will
196+ fall back to using increasing integers.
197+
198+ choice_value
199+ ~~~~~~~~~~~~
200+
201+ .. versionadded :: 2.7
202+ The ``choice_value `` option was introduced in Symfony 2.7.
203+
204+ **type **: ``string ``, ``callable `` or :class: `Symfony\\ Component\\ PropertyAccess\\ PropertyPath ` **default **: id
205+
206+ As for the ``choice_name `` option, ``choice_value `` uses the id by default.
207+ It allows an optimization in the :class: ``Symfony\\ Bridge\\ Doctrine\\ Form\\ ChoiceList\\ Loader\\ DoctrineChoiceLoader` ` which will
208+ only load the ids passed as values while the form submission.
209+ It prevents all non submitted entities to be loaded from the database, even
210+ when defining the ``query_builder `` option.
211+ If it may be useful to set this option using an entity's property as string
212+ value (e.g for some API), you will gain performances by letting this option set
213+ by default.
214+
215+ .. note ::
216+
217+ If the id cannot be read, for BC, the component checks if the class implements
218+ ``__toString() `` and will use an incremental integer otherwise.
219+
186220choices
187221~~~~~~~
188222
@@ -208,12 +242,8 @@ type:
208242
209243.. include :: /reference/forms/types/options/choice_attr.rst.inc
210244
211- .. include :: /reference/forms/types/options/choice_name.rst.inc
212-
213245.. include :: /reference/forms/types/options/choice_translation_domain.rst.inc
214246
215- .. include :: /reference/forms/types/options/choice_value.rst.inc
216-
217247.. include :: /reference/forms/types/options/expanded.rst.inc
218248
219249.. include :: /reference/forms/types/options/group_by.rst.inc
0 commit comments