retrieving object information with Doctrine
- by ajsie
i want to fetch information from the database using objects.
i really like this approach cause this is more OOP:
$user = Doctrine_Core::getTable('User')->find(1);
echo $user->Email['address'];
echo $user->Phonenumbers[0]->phonenumber;
rather than:
$q = Doctrine_Query::create()
->from('User u')
->leftJoin('u.Email e')
->leftJoin('u.Phonenumbers p')
->where('u.id = ?', 1);
$user = $q->fetchOne();
echo $user->Email['address'];
echo $user->Phonenumbers[0]['phonenumber'];
the problem is that the first one uses 3 queries (3 different tables), while the second one uses only 1 (and is therefore recommended technique).
but i feel that it destroys the object oriented design. cause ORM is meant to give us an OOP approach so that we could focus on objects and not the relational database. but now they want us to go back to use SQL like pattern.
there isn't a way to get information form multiple tables not using DQL?
the above examples are taken from the documentation:
doctrine