Example #1
0
 /**
  * @param $columns
  * @param $referencedTable
  * @param array $referencedColumns
  * @param array $options
  * @return $this
  */
 public function addForeignKey($columns, $referencedTable, $referencedColumns = ['id'], $options = [])
 {
     $foreignKey = new ForeignKey();
     if (!is_array($referencedColumns)) {
         $referencedColumns = array($referencedColumns);
     }
     $foreignKey->setReferenceColumns($referencedColumns);
     if ($referencedTable instanceof Table) {
         $foreignKey->setReferenceTable($referencedTable);
     } else {
         $foreignKey->setReferenceTable(new Table($referencedTable, [], $this->mapper));
     }
     $foreignKey->setColumns($columns);
     $foreignKey->setOptions($options);
     $this->foreignKeys[] = $foreignKey;
     return $this;
 }