Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP ORMs and optimized relationship queries
    primarykey
    data
    text
    <p>I need a PHP ORM to work with relations well. Please consider code below in Zend:</p> <pre class="lang-php prettyprint-override"><code>$persons = new Persons(); $person = $persons-&gt;find(5)-&gt;current(); echo 'Name: '.$person-&gt;fullname; $phones = $person-&gt;findDependentRowset('Phones'); foreach($phones as $phone) echo 'Phone: '.$phone-&gt;phonenumber; </code></pre> <p>Or code below in xPDO:</p> <pre class="lang-php prettyprint-override"><code>$person = $xpdo-&gt;getObject('Persons', 5); echo 'Name: '.$person-&gt;get('fullname'); $phones = $person-&gt;getMany('Phones'); foreach($phones as $phone) echo 'Phone: '.$phone-&gt;get('phonenumber'); </code></pre> <p>in both scripts, ORMs executes two queries as below:</p> <pre class="lang-sql prettyprint-override"><code>SELECT * FROM persons WHERE id=5; SELECT * FROM phones WHERE person=5; </code></pre> <p>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:</p> <pre class="lang-php prettyprint-override"><code>$person = $xpdo-&gt;getObjectGraph('Persons', '{"Phones":{}}', 5); echo 'Name: '.$person-&gt;get('fullname'); foreach($person-&gt;Phones as $phone) echo 'Phone: '.$phone-&gt;get('phonenumber'); </code></pre> <p>which executes this query:</p> <pre class="lang-sql prettyprint-override"><code>SELECT * FROM persons LEFT JOIN phones ON phones.person=persons.id WHERE persons.id=5 </code></pre> <p>This is great but its not possible to set fields to get from tables! it means in this case xPDO use <strong>"SELECT * "</strong> so if i get an object and its 4 relations, i will get all fields of all these tables!</p> <p>So i need an ORM to execute query below for example above:</p> <pre class="lang-sql prettyprint-override"><code>SELECT persons.fullname , phones.phonenumber FROM persons LEFT JOIN phones ON phones.person=persons.id WHERE persons.id=5 </code></pre> <p>Doctrine can do it via DQL but i think Doctrine is not good for personal projects. Is there any PHP ORM to do this?</p> <p>Thanks AHHP</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload