method getCreateConstraints documentation in bbn\Db\Languages\Sql
function(string $table, array $model = NULL)
{
$st = '';
if (!$model) {
$model = $this->modelize($table);
}
if ($model && !empty($model['keys'])) {
$constraints = array_filter(
$model['keys'], function ($a) {
return !empty($a['ref_table']) && isset($a['columns']) && (count($a['columns']) === 1)
&& !empty($a['constraint']) && !empty($a['ref_column']);
}
);
if ($last = count($constraints)) {
$st .= 'ALTER TABLE ' . $this->escape($table) . PHP_EOL;
$i = 0;
foreach ($constraints as $name => $key) {
$i++;
$st .= ' ADD ' .
'CONSTRAINT ' . $this->escape($key['constraint']) . ' FOREIGN KEY (' . $this->escape($key['columns'][0]) . ') ' .
'REFERENCES ' . $this->escape($key['ref_table']) . ' (' . $this->escape($key['ref_column']) . ')' .
(!empty($key['delete']) ? ' ON DELETE ' . $key['delete'] : '') .
(!empty($key['update']) ? ' ON UPDATE ' . $key['update'] : '') .
($i === $last ? ';' : ',' . PHP_EOL);
}
}
}
return $st;
}
BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2023
BBN Solutions