Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess I got it working at least for hierarchial Model structure.</p> <p>This is how it was done:</p> <pre><code>class Model_Object extends hierarchy\Model_Hierarchy { public $table = 'object'; function init(){ parent::init(); $this-&gt;debug(); // for debugging $this-&gt;addField('name'); $this-&gt;addHook('beforeDelete',$this); } function beforeDelete($m) { // === This is how you can throw exception if there is at least one child record === // if($m-&gt;ref('Object')-&gt;count()-&gt;getOne()) throw $this-&gt;exception('Have child records!'); // === This is how you can delete child records, but use this only if you're sure that there are no child/child records === // $m-&gt;ref('Object')-&gt;deleteAll(); // === This is how you can delete all child records including child/child records (hierarcialy) === // Should use loop if we're not sure if there will be child/child records // We have to use newInstance, otherwise we travel away from $m and can't "get back to parent" when needed $c = $m-&gt;newInstance()-&gt;load($m-&gt;id)-&gt;ref('Object'); // maybe $c = $m-&gt;newInstance()-&gt;loadBy('parent_id',$m-&gt;id); will work too? foreach($c as $junk){ $c-&gt;delete(); } return $this; } } </code></pre> <p>Important things here are:<br> * extend hierarchy\Model_Hierarchy class not Model_Table<br> * use appropriate method in beforeDelete hook<br> * * restrict delete if we have children - throw exception<br> * * deleteAll - use it when you're sure that there will be no child/child records<br> * * newInstance + loop + delete - use it when you have to delete records (even child/child/...) hierarchialy </p> <p>Maybe some of you have a better solution?</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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