retrieving object information with Doctrine

Posted by ajsie on Stack Overflow See other posts from Stack Overflow or by ajsie
Published on 2010-04-17T22:54:56Z Indexed on 2010/04/17 23:03 UTC
Read the original article Hit count: 269

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about orm

Related posts about doctrine