Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing some extra details from #6444 #6600

Merged
merged 1 commit into from
Jul 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions reference/forms/types/entity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,16 @@ return a ``QueryBuilder``.
Overridden Options
------------------

choice_name
~~~~~~~~~~~
.. include:: /reference/forms/types/options/choice_name.rst.inc

.. versionadded:: 2.7
The ``choice_name`` option was introduced in Symfony 2.7.

**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id

By default the name of each field is the id of the entity, if it can be read
from the class metadata by an internal id reader. Otherwise the process will
fall back to using increasing integers.

choice_value
~~~~~~~~~~~~
In the ``EntityType``, this defaults to the ``id`` of the entity, if it can
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question: does "the id of the entity" refer explicitly to a property called id or does it refer to the primary key value, whatever the property is called (and it works even for composite primary keys)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it refers to the PK, but I believe none of this works the same with composite PK's, but I'm not sure exactly what happens on that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works at the moment the identifier is in a single column (any PK or association), see https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php#L112 for more details.

be read. Otherwise, it falls back to using auto-incrementing integers.

.. versionadded:: 2.7
The ``choice_value`` option was introduced in Symfony 2.7.

**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id

As for the ``choice_name`` option, ``choice_value`` uses the id by default.
It allows an optimization in the :class:``Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\Loader\\DoctrineChoiceLoader`` which will
only load the ids passed as values while the form submission.
It prevents all non submitted entities to be loaded from the database, even
when defining the ``query_builder`` option.
If it may be useful to set this option using an entity's property as string
value (e.g for some API), you will gain performances by letting this option set
by default.

.. note::
.. include:: /reference/forms/types/options/choice_value.rst.inc

If the id cannot be read, for BC, the component checks if the class implements
``__toString()`` and will use an incremental integer otherwise.
In the ``EntityType``, this is overridden to use the ``id`` by default. When the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @weaverryan, I agree with those steps. However this information in choice_name is quite important and should remain in a "note" or "caution" block IMHO.

Because as you said in your description, using this option prevents the optimization when loading entities.
Also, saying that the __toString method or integers (as strings) should be kept since in fact, selecting choices (empty_data, API, ...) really depends on this setting.

Note that there is some work in progress (and planned to be) where feedbacks would be very welcome: #6265 and #6446.

Besides that 👍

``id`` is used, Doctrine only queries for the objects for the ids that were actually
submitted.

choices
~~~~~~~
Expand Down