I need a PHP ORM to work with relations well. Please consider code below in Zend:
$persons = new Persons();
$person = $persons->find(5)->current();
echo Name: .$person->fullname;
$phones = $person->findDependentRowset( Phones );
foreach($phones as $phone)
echo Phone: .$phone->phonenumber;
Or code below in xPDO:
$person = $xpdo->getObject( Persons , 5);
echo Name: .$person->get( fullname );
$phones = $person->getMany( Phones );
foreach($phones as $phone)
echo Phone: .$phone->get( phonenumber );
in both scripts, ORMs executes two queries as below:
SELECT * FROM persons WHERE id=5;
SELECT * FROM phones WHERE person=5;
It means one query for main object and one query for each relation but what i need is using ONE query for main object and its relations! xPDO can do it as below:
$person = $xpdo->getObjectGraph( Persons , {"Phones":{}} , 5);
echo Name: .$person->get( fullname );
foreach($person->Phones as $phone)
echo Phone: .$phone->get( phonenumber );
执行这一询问:
SELECT * FROM persons
LEFT JOIN phones ON phones.person=persons.id
WHERE persons.id=5
This is great but its not possible to set fields to get from tables! it means in this case xPDO use "SELECT * " so if i get an object and its 4 relations, i will get all fields of all these tables!
因此,如上所述,需要一个办公室来执行询问:
SELECT persons.fullname , phones.phonenumber FROM persons
LEFT JOIN phones ON phones.person=persons.id
WHERE persons.id=5
Doctrine can do it via DQL but i think Doctrine is not good for personal projects. Is there any PHP ORM to do this?
Thanks AHHP