From 238c2658227717800b4a15304b7f33d323052d9d Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Tue, 28 Mar 2017 12:43:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0addNullableMorphs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/Table.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/db/Table.php b/src/db/Table.php index 1aae97b..cf4daa9 100644 --- a/src/db/Table.php +++ b/src/db/Table.php @@ -84,6 +84,14 @@ class Table extends \Phinx\Db\Table return $this; } + public function addNullableMorphs($name, $indexName = null) + { + $this->addColumn(Column::unsignedInteger("{$name}_id")->setNullable()); + $this->addColumn(Column::string("{$name}_type")->setNullable()); + $this->addIndex(["{$name}_id", "{$name}_type"], ['name' => $indexName]); + return $this; + } + /** * @param string $createdAtColumnName * @param string $updatedAtColumnName