forked from Wavyzz/dolibarr
Generate the foreign key into key.sql file
This commit is contained in:
@@ -301,11 +301,20 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='',
|
|||||||
foreach($object->fields as $key => $val)
|
foreach($object->fields as $key => $val)
|
||||||
{
|
{
|
||||||
$i++;
|
$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.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");";
|
||||||
$texttoinsert.= "\n";
|
$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';
|
$texttoinsert.= '-- END MODULEBUILDER INDEXES';
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class MyObject extends CommonObject
|
|||||||
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
|
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
|
||||||
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
|
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
|
||||||
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
|
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
|
||||||
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
|
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510, 'foreignkey'=>'llx_user.rowid'),
|
||||||
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
|
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
|
||||||
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
|
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
|
||||||
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
|
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
ALTER TABLE llx_mymodule_myobject ADD INDEX idx_fieldobject (fieldobject);
|
ALTER TABLE llx_mymodule_myobject ADD INDEX idx_fieldobject (fieldobject);
|
||||||
-- END MODULEBUILDER INDEXES
|
-- END MODULEBUILDER INDEXES
|
||||||
|
|
||||||
--ALTER TABLE llx_mymodule_myobject ADD UNIQUE INDEX uk_mymodule_myobject_fieldxyz(fieldx, fieldy);
|
--ALTER TABLE llx_mymodule_myobject ADD UNIQUE INDEX uk_mymodule_myobject_fieldxy(fieldx, fieldy);
|
||||||
|
|
||||||
--ALTER TABLE llx_mymodule_myobject ADD CONSTRAINT llx_mymodule_myobject_field_id FOREIGN KEY (fk_field) REFERENCES llx_myotherobject(rowid);
|
--ALTER TABLE llx_mymodule_myobject ADD CONSTRAINT llx_mymodule_myobject_fk_field FOREIGN KEY (fk_field) REFERENCES llx_mymodule_myotherobject(rowid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user