Skip to content

Commit 92997cc

Browse files
committed
Prefix foreign key name with table name
1 parent 060b053 commit 92997cc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Kalnoy/Nestedset/NestedSet.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@ static public function columns(Blueprint $table, $primaryKey = 'id')
2121
$table->index(array(Node::LFT, Node::RGT, Node::PARENT_ID), 'nested_set_index');
2222

2323
$table
24-
->foreign(Node::PARENT_ID, 'nested_set_foreign')
24+
->foreign(Node::PARENT_ID, self::getForeignKeyName($table->getTable()))
2525
->references($primaryKey)
2626
->on($table->getTable())
2727
->onDelete('cascade');
2828
}
2929

30+
/**
31+
* Get foreign key name for the table.
32+
*
33+
* @param string $table
34+
*
35+
* @return string
36+
*/
37+
protected static function getForeignKeyName($table)
38+
{
39+
return $table.'_nested_set_foreign';
40+
}
41+
3042
/**
3143
* Drop NestedSet columns.
3244
*

0 commit comments

Comments
 (0)