1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/manual/docs/Working with objects - Component overview - Collection - Loading related records.php

25 lines
656 B
PHP
Raw Normal View History

2007-04-14 01:49:11 +04:00
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.
2007-04-14 01:49:11 +04:00
<code type="php">
$users = $conn->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;
}
</code>