diff --git a/manual/codes/Basic Components - Collection - Loading related records.php b/manual/codes/Basic Components - Collection - Loading related records.php new file mode 100644 index 000000000..64715cecd --- /dev/null +++ b/manual/codes/Basic Components - Collection - Loading related records.php @@ -0,0 +1,20 @@ +query("FROM User"); + +// now lets load phonenumbers for all users + +$users->loadRelated("Phonenumber"); + +foreach($users as $user) { + print $user->Phonenumber->phonenumber; + // no additional db queries needed here +} + +// the loadRelated works an any relation, even associations: + +$users->loadRelated("Group"); + +foreach($users as $user) { + print $user->Group->name; +} +?> diff --git a/manual/docs/Basic Components - Collection - Loading related records.php b/manual/docs/Basic Components - Collection - Loading related records.php new file mode 100644 index 000000000..24b8ebd42 --- /dev/null +++ b/manual/docs/Basic Components - Collection - Loading related records.php @@ -0,0 +1,3 @@ +Doctrine provides means for effiently retrieving all related records for all record elements. That means +when you have for example a collection of users you can load all phonenumbers for all users by simple calling +the loadRelated() method.