Example #1
0
 protected function getForeignKeyDefinitionSql($tableName, ForeignKey $key)
 {
     $quote = function ($val) {
         return $this->conn->quoteIdentifier($val);
     };
     $cols = array_map($quote, $key->getColumns());
     $ref = array_map($quote, $key->getRefColumns());
     $sql = 'CONSTRAINT ' . $this->conn->quoteIdentifier($key->getName($this->conn->applyPrefix($tableName)));
     $sql .= ' FOREIGN KEY (' . implode(', ', $cols) . ') REFERENCES ';
     $sql .= $this->conn->quoteIdentifier($key->getRefTable());
     $sql .= ' (' . implode(', ', $ref) . ')';
     if (NULL !== ($update = $key->getOnUpdate())) {
         $sql .= ' ON UPDATE ' . $update;
     }
     if (NULL !== ($delete = $key->getOnDelete())) {
         $sql .= ' ON DELETE ' . $delete;
     }
     return $sql;
 }
Example #2
0
 protected function getForeignKeyDefinitionSql($tableName, ForeignKey $key)
 {
     $quote = function ($val) {
         return $this->conn->quoteIdentifier($val);
     };
     $cols = array_map($quote, $key->getColumns());
     $ref = array_map($quote, $key->getRefColumns());
     $sql = 'CONSTRAINT ' . $this->conn->quoteIdentifier($key->getName($this->conn->applyPrefix($tableName)));
     $sql .= ' FOREIGN KEY (' . implode(', ', $cols) . ') REFERENCES ';
     $sql .= $this->conn->quoteIdentifier($key->getRefTable());
     $sql .= ' (' . implode(', ', $ref) . ')';
     // NO ACTION is equal to RESTRICT but can be deferred.
     // http://stackoverflow.com/a/3283095
     if (NULL !== ($update = $key->getOnUpdate())) {
         $sql .= ' ON UPDATE ' . ($update === 'RESTRICT' ? 'NO ACTION' : $update);
     }
     if (NULL !== ($delete = $key->getOnDelete())) {
         $sql .= ' ON DELETE ' . ($delete === 'RESTRICT' ? 'NO ACTION' : $delete);
     }
     $sql .= ' DEFERRABLE INITIALLY IMMEDIATE';
     return $sql;
 }