示例#1
0
 public function testCascadeAndNoAction()
 {
     $foreignKey = new ForeignKey('foreign_key_id', 'foreign_table', 'id', 'Cascade', 'No Action');
     $this->assertEquals('foreign_key_id', $foreignKey->getName());
     $this->assertCount(1, $foreignKey->getColumns());
     $this->assertEquals(['foreign_key_id'], $foreignKey->getColumns());
     $this->assertEquals('foreign_table', $foreignKey->getReferencedTable());
     $this->assertCount(1, $foreignKey->getReferencedColumns());
     $this->assertEquals(['id'], $foreignKey->getReferencedColumns());
     $this->assertEquals('CASCADE', $foreignKey->getOnDelete());
     $this->assertEquals('NO ACTION', $foreignKey->getOnUpdate());
 }
示例#2
0
 protected function createForeignKey(ForeignKey $foreignKey, Table $table)
 {
     $columns = [];
     foreach ($foreignKey->getColumns() as $column) {
         $columns[] = $this->escapeString($column);
     }
     $referencedColumns = [];
     foreach ($foreignKey->getReferencedColumns() as $column) {
         $referencedColumns[] = $this->escapeString($column);
     }
     $constraint = 'CONSTRAINT ' . $this->escapeString($table->getName() . '_' . $foreignKey->getName());
     $constraint .= ' FOREIGN KEY (' . implode(',', $columns) . ')';
     $constraint .= ' REFERENCES ' . $this->escapeString($foreignKey->getReferencedTable()) . ' (' . implode(',', $referencedColumns) . ')';
     if ($foreignKey->getOnDelete() != ForeignKey::DEFAULT_ACTION) {
         $constraint .= ' ON DELETE ' . $foreignKey->getOnDelete();
     }
     if ($foreignKey->getOnUpdate() != ForeignKey::DEFAULT_ACTION) {
         $constraint .= ' ON UPDATE ' . $foreignKey->getOnUpdate();
     }
     return $constraint;
 }