diff --git a/includes/qcodo/_core/codegen/QDatabaseCodeGen.class.php b/includes/qcodo/_core/codegen/QDatabaseCodeGen.class.php index 25e6546c..dc52c8a8 100644 --- a/includes/qcodo/_core/codegen/QDatabaseCodeGen.class.php +++ b/includes/qcodo/_core/codegen/QDatabaseCodeGen.class.php @@ -1056,9 +1056,9 @@ protected function GetForeignKeyForSqlRelationshipDefinition($strTableName, $str // Add Constraint $strPattern .= '(add[\s]+)?(constraint[\s]+'; - $strPattern .= '[\[\`\'\"]?(' . $this->strPatternKeyName . ')[\]\`\'\"]?[\s]+)?'; + $strPattern .= '[\[\`\'\"]?(' . $this->strPatternKeyName . ')[\]\`\'\"]?[\s]+)?[\s]*'; // Foreign Key - $strPattern .= 'foreign[\s]+key[\s]*\('; + $strPattern .= 'foreign[\s]+key[\s]*(' . $this->strPatternKeyName . ')[\s]*\('; $strPattern .= '([^)]+)\)[\s]*'; // References $strPattern .= 'references[\s]+'; @@ -1070,11 +1070,11 @@ protected function GetForeignKeyForSqlRelationshipDefinition($strTableName, $str // Perform the RegExp preg_match($strPattern, $strLine, $strMatches); - if (count($strMatches) == 8) { - $strColumnName = trim($strMatches[5]); - $strReferenceTableName = trim($strMatches[6]); - $strReferenceColumnName = trim($strMatches[7]); - $strFkName = $strMatches[4]; + if (count($strMatches) == 9) { + $strColumnName = trim($strMatches[6]); + $strReferenceTableName = trim($strMatches[7]); + $strReferenceColumnName = trim($strMatches[8]); + $strFkName = $strMatches[5]; if (!$strFkName) $strFkName = sprintf('virtualfk_%s_%s', $strTableName, $strColumnName);