Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple level dependency models in Zend Framework
    primarykey
    data
    text
    <p>I'm developing an application in Zend Framework to handle the rentals for a commercial property rental company. The company has multiple buildings which each have multiple floors, which each have multiple units. </p> <p>The models I've setup just extend <code>Zend_Db_Table_Abstract</code>, and I've set them up with <code>$_dependentTables</code> and <code>$_referenceMap</code>s with cascading delete, such that when I delete a floor, all the units within it are deleted too, and when I delete a building, all the floors in it are deleted. However, when I delete a building and the floors are deleted, the delete is not cascaded through to each floor's units. (edit: I'm using MySQL, so I am not able to use referencial integrity at the db level.) </p> <p>I've looked at how the deletes are cascaded, and it appears they aren't cascading because the cacaded deletes are executed using a <code>Zend_Db_Table</code> object, not a <code>Zend_Db_Table_Row</code> object (which you have to use to achieve cascading).</p> <p>Is there any way I can update the system so that the delete cascades all the way down? Is there a way I can modify the relationships of my classes, or would I need to use something like Doctrine?</p> <p>(I guess I could override the <code>delete()</code> method for the row of each table or something, but I just wondered if this is possible using the relationships functionality of ZF?)</p> <p>If it helps, here's the relevant parts of the class definitions:</p> <pre><code>class Buildings extends Zend_Db_Table { protected $_dependentTables = array('Floors'); } class Floors extends Zend_Db_Table { protected $_dependentTables = array('Units'); protected $_referenceMap = array( 'Building' =&gt; array( 'columns' =&gt; 'building_id', 'refTableClass' =&gt; 'Buildings', 'refColumns' =&gt; 'id', 'onDelete' =&gt; self::CASCADE, )); } class Units extends Zend_Db_Table { protected $_referenceMap = array( 'Floor' =&gt; array( 'columns' =&gt; 'floor_id', 'refTableClass' =&gt; 'Floors', 'refColumns' =&gt; 'id', 'onDelete' =&gt; self::CASCADE, )); } </code></pre>
    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