minhas
minhas

Reputation: 55

Kohana ORM cascade delete

Is there any method in Kohana 3.2 ORM for cascade delete.I am a beginner in kohana so any one can help me in this matter?

Upvotes: 2

Views: 1349

Answers (2)

EricMakesStuff
EricMakesStuff

Reputation: 521

To cascade deletes, override the delete() method in your model:

class Model_Alpha extends ORM
{
  protected $_has_many = array(
    'beta' => array(
      'model' => 'beta',
      'foreign_key' => 'alpha_id',
    ),
    'gamma' => array(
      'model' => 'gamma',
      'foreign_key' => 'alpha_id',
    ),
  );

  function delete()
  {
    foreach($this->beta->find_all() as $entry)
      $entry->delete();
    foreach($this->gamma->find_all() as $entry)
      $entry->delete();
    parent::delete();
  }
}

You can then cascade further by overriding the delete() method on the models you're deleting.

Upvotes: 1

matino
matino

Reputation: 17725

I'm afraid there isn't in Kohana. If you really need one, you should apply it on the database level (ON DELETE CASCADE)

Upvotes: 2

Related Questions