tags:

views:

103

answers:

1

If I create a new Doctrine object, with lots of relations, should I save() these relations before assigning them to newly created object? E.g.

$main = new Main();
$child = new Child();
$main->child_rel = $child; // do I need to save the child obj explicitly?
$main->save();

I assumed that parent will automatically call cascading saves, but this doesn't seem to be the case for a newly instantiated parent object.

How does it really work?

A: 

Doctrine take care of everything and save related records if needed. By the way, you don't need to instanciate an related object. You can use this syntax :

$user->Email->address = '[email protected]';
$user->save();

In the case of one-to-many and many-to-many relationships :

$user->Phonenumbers[]->phonenumber = '123 123';
$user->Phonenumbers[]->phonenumber = '456 123';
$user->Phonenumbers[]->phonenumber = '123 777';
$user->save();

More infos on the doctrine documentation.

DuoSRX