diff --git a/manual/new/docs/en/working-with-objects/dealing-with-relations.txt b/manual/new/docs/en/working-with-objects/dealing-with-relations.txt index 070657d74..2faff0f00 100644 --- a/manual/new/docs/en/working-with-objects/dealing-with-relations.txt +++ b/manual/new/docs/en/working-with-objects/dealing-with-relations.txt @@ -39,9 +39,11 @@ $user->save(); +++ Retrieving related records -You can retrieve related records by the very same {{Doctrine_Record}} methods you've already propably used for accessing record properties. When accessing related record you just simply use the class names. +You can retrieve related records by the very same {{Doctrine_Record}} methods as in the previous subchapter. Please note that whenever you access a related component that isn't already loaded Doctrine uses one SQL SELECT statement for the fetching, hence the following example executes 4 SQL SELECTs. +$user = $conn->getTable('User')->find(5); + print $user->Email['address']; print $user->Phonenumber[0]->phonenumber; @@ -49,6 +51,23 @@ print $user->Phonenumber[0]->phonenumber; print $user->Group[0]->name; +Much more efficient way of doing this is using DQL. The following example uses only one SQL query for the retrieval of related components. + + +$user = Doctrine_Query::create() + ->from('User u') + ->leftJoin('u.Email e') + ->leftJoin('u.Phonenumber p') + ->leftJoin('u.Group g') + ->execute(); + +print $user->Email['address']; + +print $user->Phonenumber[0]->phonenumber; + +print $user->Group[0]->name; + + +++ Updating related records