2
0
forked from Wavyzz/dolibarr

Generate the foreign key into key.sql file

This commit is contained in:
Laurent Destailleur
2018-03-27 23:26:20 +02:00
parent 56c8ee8978
commit 7a45527983
3 changed files with 13 additions and 4 deletions

View File

@@ -301,11 +301,20 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='',
foreach($object->fields as $key => $val)
{
$i++;
if ($val['index'])
if (! empty($val['index']))
{
$texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");";
$texttoinsert.= "\n";
}
if (! empty($val['foreignkey']))
{
$tmp=explode('.',$val['foreignkey']);
if (! empty($tmp[0]) && ! empty($tmp[1]))
{
$texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");";
$texttoinsert.= "\n";
}
}
}
}
$texttoinsert.= '-- END MODULEBUILDER INDEXES';