@@ -1234,6 +1234,8 @@ objects. For example, a registration form may contain data belonging to
12341234a ``User `` object as well as many ``Address `` objects. Fortunately, this
12351235is easy and natural with the Form component.
12361236
1237+ .. _forms-embedding-single-object :
1238+
12371239Embedding a Single Object
12381240~~~~~~~~~~~~~~~~~~~~~~~~~
12391241
@@ -1263,6 +1265,7 @@ Next, add a new ``category`` property to the ``Task`` class::
12631265
12641266 /**
12651267 * @Assert\Type(type="Acme\TaskBundle\Entity\Category")
1268+ * @Assert\Valid()
12661269 */
12671270 protected $category;
12681271
@@ -1279,6 +1282,12 @@ Next, add a new ``category`` property to the ``Task`` class::
12791282 }
12801283 }
12811284
1285+ .. tip ::
1286+
1287+ The ``Valid `` Constraint has been added to the property ``category ``. This
1288+ cascades the validation to the corresponding entity. If you omit this constraint
1289+ the child entity would not be validated.
1290+
12821291Now that your application has been updated to reflect the new requirements,
12831292create a form class so that a ``Category `` object can be modified by the user::
12841293
@@ -1326,16 +1335,7 @@ class:
13261335 }
13271336
13281337 The fields from ``CategoryType `` can now be rendered alongside those from
1329- the ``TaskType `` class. To activate validation on CategoryType, add
1330- the ``cascade_validation `` option to ``TaskType ``::
1331-
1332- public function setDefaultOptions(OptionsResolverInterface $resolver)
1333- {
1334- $resolver->setDefaults(array(
1335- 'data_class' => 'Acme\TaskBundle\Entity\Task',
1336- 'cascade_validation' => true,
1337- ));
1338- }
1338+ the ``TaskType `` class.
13391339
13401340Render the ``Category `` fields in the same way as the original ``Task `` fields:
13411341
0 commit comments