-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileBehavior.php
More file actions
39 lines (32 loc) · 1002 Bytes
/
FileBehavior.php
File metadata and controls
39 lines (32 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Creonit\PropelFileBehavior;
use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\ForeignKey;
class FileBehavior extends Behavior
{
protected $parameters = [
'parameter' => 'file_id',
];
protected function addFileColumn($columnName){
$table = $this->getTable();
$table->addColumn([
'name' => $columnName,
'type' => 'integer'
]);
$fk = new ForeignKey();
$fk->setForeignTableCommonName('file');
$fk->setForeignSchemaName($table->getSchema());
$fk->setDefaultJoin('LEFT JOIN');
$fk->setOnDelete(ForeignKey::SETNULL);
$fk->setOnUpdate(ForeignKey::CASCADE);
$fk->addReference($columnName, 'id');
$table->addForeignKey($fk);
}
public function modifyTable()
{
$columns = explode(',', $this->getParameter('parameter'));
foreach ($columns as $column){
$this->addFileColumn(trim($column));
}
}
}