Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schema generator #1467

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ protected function addVersionTable()
$table = $this->getTable();
$database = $table->getDatabase();
$versionTableName = $this->getParameter('version_table') ? $this->getParameter('version_table') : ($table->getOriginCommonName() . '_version');
if (!$database->hasTable($versionTableName)) {
$this->versionTable = $database->getTable($versionTableName);
if (empty($this->versionTable)) {
// create the version table
$versionTable = $database->addTable([
'name' => $versionTableName,
Expand Down Expand Up @@ -188,8 +189,6 @@ protected function addVersionTable()
$versionColumn->setNotNull(true);
$versionColumn->setPrimaryKey(true);
$this->versionTable = $versionTable;
} else {
$this->versionTable = $database->getTable($versionTableName);
}
}

Expand All @@ -211,7 +210,7 @@ public function addForeignKeyVersionColumns()
}

foreach ($this->getVersionableReferrers() as $fk) {
$fkTableName = $fk->getTable()->getName();
$fkTableName = $fk->getTable()->getCommonName();
$fkIdsColumnName = $fkTableName . '_ids';
if (!$versionTable->hasColumn($fkIdsColumnName)) {
$versionTable->addColumn([
Expand Down Expand Up @@ -287,7 +286,7 @@ public function getVersionableReferrers()
*/
public function getReferrerIdsColumn(ForeignKey $fk)
{
$fkTableName = $fk->getTable()->getName();
$fkTableName = $fk->getTable()->getCommonName();
$fkIdsColumnName = $fkTableName . '_ids';

return $this->versionTable->getColumn($fkIdsColumnName);
Expand All @@ -300,7 +299,7 @@ public function getReferrerIdsColumn(ForeignKey $fk)
*/
public function getReferrerVersionsColumn(ForeignKey $fk)
{
$fkTableName = $fk->getTable()->getName();
$fkTableName = $fk->getTable()->getCommonName();
$fkIdsColumnName = $fkTableName . '_versions';

return $this->versionTable->getColumn($fkIdsColumnName);
Expand Down
12 changes: 12 additions & 0 deletions src/Propel/Generator/Manager/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ protected function includeExternalSchemas(DOMDocument $dom, $srcDir)

$externalSchema->parentNode->removeChild($externalSchema);

// when this is not readable like './some/other/schema.xml' or '../../extra/schema.xml'
if (!is_readable($include)) {
// find in the relative path
foreach ($this->getGeneratorConfig()->getConfigProperty('paths') as $path) {
if (is_readable($path . DIRECTORY_SEPARATOR . $include)) {
$include = realpath($path . DIRECTORY_SEPARATOR . $include);

break;
}
}
}

if (!is_readable($include)) {
throw new BuildException("External schema '$include' does not exist");
}
Expand Down
Loading