@@ -1234,6 +1234,8 @@ objects. For example, a registration form may contain data belonging to
1234
1234
a ``User `` object as well as many ``Address `` objects. Fortunately, this
1235
1235
is easy and natural with the Form component.
1236
1236
1237
+ .. _forms-embedding-single-object :
1238
+
1237
1239
Embedding a Single Object
1238
1240
~~~~~~~~~~~~~~~~~~~~~~~~~
1239
1241
@@ -1263,6 +1265,7 @@ Next, add a new ``category`` property to the ``Task`` class::
1263
1265
1264
1266
/**
1265
1267
* @Assert\Type(type="Acme\TaskBundle\Entity\Category")
1268
+ * @Assert\Valid()
1266
1269
*/
1267
1270
protected $category;
1268
1271
@@ -1279,6 +1282,12 @@ Next, add a new ``category`` property to the ``Task`` class::
1279
1282
}
1280
1283
}
1281
1284
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
+
1282
1291
Now that your application has been updated to reflect the new requirements,
1283
1292
create a form class so that a ``Category `` object can be modified by the user::
1284
1293
@@ -1326,16 +1335,7 @@ class:
1326
1335
}
1327
1336
1328
1337
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.
1339
1339
1340
1340
Render the ``Category `` fields in the same way as the original ``Task `` fields:
1341
1341
0 commit comments