ActiveRecord.php
public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            if ($this->media) {
                foreach ($this->media as $media)  {
                    $media->delete();
                }
            }

            return true;
        }

        return false;
    }
public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            if ($this->media) {
                foreach ($this->media as $media)  {
                    $media->delete();
                }
            }

            return true;
        }

        return false;
    }
This method is invoked before deleting a record.
The default implementation raises the [[EVENT_BEFORE_DELETE]] event.