From 6af779d51d6c3c0e37722527968c7693680cb742 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 29 Oct 2013 13:28:59 +0100 Subject: [PATCH 1/5] Add note about the property attribute (Property Accessor) I think we must document the fact that propety is a path which is evaluted by the PropertyAccessor component. --- reference/forms/types/entity.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index f74f736e61b..3b9a50a9302 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -96,6 +96,23 @@ This is the property that should be used for displaying the entities as text in the HTML element. If left blank, the entity object will be cast into a string and so must have a ``__toString()`` method. +Note: ``property`` is the property path used to display the option. So you +can use anything supported by the :doc:`PropertyAccessor component` + +Usage sample: + + $builder->add('gender', 'entity', array( + 'class' => 'MyBundle:Gender', + 'property' => 'translations[en].name', + 'query_builder' => function(EntityRepository $er) { + return $er->createQueryBuilder('g') + ->join('g.translations', 't') + ->where('t.locale = :locale') + ->orderBy('t.name', 'ASC') + ->setParameter('locale', 'en'); + }, + )); + group_by ~~~~~~~~ From 7d65feda897cc8bf11f9c7bae8f10b7ab6ca2f46 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Wed, 5 Mar 2014 20:42:11 +0100 Subject: [PATCH 2/5] Update entity.rst --- reference/forms/types/entity.rst | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index 3b9a50a9302..a6d233a696d 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -96,22 +96,23 @@ This is the property that should be used for displaying the entities as text in the HTML element. If left blank, the entity object will be cast into a string and so must have a ``__toString()`` method. -Note: ``property`` is the property path used to display the option. So you -can use anything supported by the :doc:`PropertyAccessor component` - -Usage sample: +.. note:: - $builder->add('gender', 'entity', array( - 'class' => 'MyBundle:Gender', - 'property' => 'translations[en].name', - 'query_builder' => function(EntityRepository $er) { - return $er->createQueryBuilder('g') - ->join('g.translations', 't') - ->where('t.locale = :locale') - ->orderBy('t.name', 'ASC') - ->setParameter('locale', 'en'); - }, - )); + The ``property`` option is the property path used to display the option. So you + can use anything supported by the :doc:`PropertyAccessor component` + + Usage sample:: + + $builder->add('gender', 'entity', array( + 'class' => 'MyBundle:Gender', + 'property' => 'translations[en].name', + 'query_builder' => function(EntityRepository $er) { + return $er->createQueryBuilder('g') + ->join('g.translations', 't', 'WITH', 't.locale = :locale') + ->orderBy('t.name', 'ASC') + ->setParameter('locale', 'en'); + }, + )); group_by ~~~~~~~~ From c097f9b9c15849cb782fbb67bed87ea2eda6fb85 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Wed, 5 Mar 2014 23:22:46 +0100 Subject: [PATCH 3/5] Update entity.rst --- reference/forms/types/entity.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index a6d233a696d..8c08da93c2a 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -99,7 +99,8 @@ cast into a string and so must have a ``__toString()`` method. .. note:: The ``property`` option is the property path used to display the option. So you - can use anything supported by the :doc:`PropertyAccessor component` + can use anything supported by the : + doc:`PropertyAccessor component ` Usage sample:: From 7496e68d165a87165c09765c9f432c8cb1a50a92 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Wed, 5 Mar 2014 23:25:16 +0100 Subject: [PATCH 4/5] Update entity.rst --- reference/forms/types/entity.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index 8c08da93c2a..7c9ad3f1a42 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -99,8 +99,8 @@ cast into a string and so must have a ``__toString()`` method. .. note:: The ``property`` option is the property path used to display the option. So you - can use anything supported by the : - doc:`PropertyAccessor component ` + can use anything supported by the + :doc:`PropertyAccessor component ` Usage sample:: From 46f1b8b1f38e23a7f80398ce7039da15238f5243 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 18 Mar 2014 21:54:50 +0100 Subject: [PATCH 5/5] Update entity.rst --- reference/forms/types/entity.rst | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index 7c9ad3f1a42..4ba1182748b 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -102,17 +102,12 @@ cast into a string and so must have a ``__toString()`` method. can use anything supported by the :doc:`PropertyAccessor component ` - Usage sample:: + For example, if the translations property is actually an associative array of + objects, each with a name property, then you could do this:: $builder->add('gender', 'entity', array( 'class' => 'MyBundle:Gender', 'property' => 'translations[en].name', - 'query_builder' => function(EntityRepository $er) { - return $er->createQueryBuilder('g') - ->join('g.translations', 't', 'WITH', 't.locale = :locale') - ->orderBy('t.name', 'ASC') - ->setParameter('locale', 'en'); - }, )); group_by