public function deleteAction(Revisions $rev) { $parent_id = $rev->parent_id; $rev->delete(); $remain = Revisions::findFirst(['parent_id = :id:', 'bind' => ['id' => $parent_id]]); if ($remain) { return $this->redirectByRoute(['for' => 'revisions.show', 'rev' => $remain->id]); } else { return $this->response->redirect('/'); } }
/** * @return Revisions */ public function findOrCreateRevision() { /** @var myModel $this */ return $this->make('revision', function () { /** @var myModel $this */ $revision = Revisions::findFirst(['file_id = :id:', 'bind' => ['id' => $this->id]]); if ($revision == null) { $revision = new Revisions(['file_id' => $this->id]); } return $revision; }); }