Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In <strong>Doctrine 1.x</strong> I've overridden the <strong><code>isValid()</code></strong> method on the concrete <code>Doctrine_Record</code> (here, <code>LineItem</code>):</p> <pre><code>public function isValid($deep = false, $hooks = true) { $q = Doctrine_Query::create() -&gt;select('co.uid') -&gt;from('Company co') -&gt;leftJoin('co.workers w') -&gt;leftJoin('co.customers cust') -&gt;leftJoin('cust.workCases wc') -&gt;where('w.uid = ?', $this-&gt;_workerUid) // This LineItem's Worker must _always_ have the same Company as this LineItem (through LineItem -&gt; WorkCase -&gt; Customer -&gt; Company) -&gt;andWhere('wc.state = ?', WorkCase::STATE_OPEN) // This LineItem's WorkCase must be open -&gt;andWhere('wc.uid = ?', $this-&gt;_caseUid); $company = $q-&gt;fetchOne(); return $company !== false &amp;&amp; parent::isValid($deep, $hooks); } </code></pre> <p>There are a few things to note here:</p> <ol> <li>I'm trying to fetch the <code>Company</code> based on some criteria (amongst others, the <code>state</code> must be "open"). The end result depends on whether I find a company that satisfies these criteria (<code>$company !== false</code>)</li> <li><code>isValid()</code> is <em>overriding</em> a deeper implementation. <strong>Always</strong> make the end result dependent on <code>parent::isValid($deep, $hooks)</code> (we must be certain that the original implementation is also happy).</li> <li>You could probably make the "fetch company record" simpler in your case.</li> </ol>
    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.
    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