Skip to content

Commit

Permalink
Merge pull request #155 from K-Phoen/fix-versioning-inheritance
Browse files Browse the repository at this point in the history
Fix: port of the PR #324 from Propel
  • Loading branch information
willdurand committed Mar 25, 2012
2 parents 13c4e82 + 623ae81 commit b525135
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected function addVersionTable()
// copy all the columns
foreach ($table->getColumns() as $column) {
$columnInVersionTable = clone $column;
$columnInVersionTable->clearInheritanceList();
if ($columnInVersionTable->hasReferrers()) {
$columnInVersionTable->clearReferrers();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Propel/Generator/Model/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ public function clearReferrers()
$this->referrers = null;
}

public function clearInheritanceList()
{
$this->inheritanceList = array();
}

/**
* Sets the domain up for specified Propel type.
*
Expand Down
17 changes: 9 additions & 8 deletions src/Propel/Generator/Util/QuickBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,19 @@ public function getClassesForTable(Table $table, array $classTargets = null)
if ($col->isEnumeratedClasses()) {
foreach ($col->getChildren() as $child) {
if ($child->getAncestor()) {
$builder = $this->getConfig()->getConfiguredBuilder('queryinheritance', $target);
$builder->setChild($child);
$class = $builder->build();
$class = "\nnamespace\n{\n" . $class . "\n}\n";
$script .= $this->fixNamespaceDeclarations($class);
}
foreach (array('objectmultiextend', 'queryinheritancestub') as $target) {
$builder = $this->getConfig()->getConfiguredBuilder($table, $target);
$builder = $this->getConfig()->getConfiguredBuilder($table, 'queryinheritance');
$builder->setChild($child);
$class = $builder->build();
$class = "\nnamespace\n{\n" . $class . "\n}\n";
$script .= $this->fixNamespaceDeclarations($class);

foreach (array('objectmultiextend', 'queryinheritancestub') as $target) {
$builder = $this->getConfig()->getConfiguredBuilder($table, $target);
$builder->setChild($child);
$class = $builder->build();
$class = "\nnamespace\n{\n" . $class . "\n}\n";
$script .= $this->fixNamespaceDeclarations($class);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public function setUp()
<parameter name="version_comment_column" value="MyComment" />
</behavior>
</table>
EOF;
QuickBuilder::buildSchema($schema2);
}

if (!class_exists('\VersionableBehaviorTest8')) {
$schema2 = <<<EOF
<database name="versionable_behavior_test_3" defaultPhpNamingMethod="nochange">
<table name="VersionableBehaviorTest8">
<column name="Id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="FooBar" type="VARCHAR" size="100" />
<column name="class_key" type="INTEGER" required="true" default="1" inheritance="single">
<inheritance key="1" class="VersionableBehaviorTest8" />
<inheritance key="2" class="VersionableBehaviorTest8Foo" extends="VersionableBehaviorTest8" />
<inheritance key="3" class="VersionableBehaviorTest8Bar" extends="VersionableBehaviorTest8Foo" />
</column>
<behavior name="versionable" />
</table>
EOF;
QuickBuilder::buildSchema($schema2);
}
Expand Down Expand Up @@ -713,4 +731,16 @@ public function testEnumField()
$this->assertEquals('novel', $o->getOneVersion(1)->getStyle(), 'First version is a novel');
$this->assertEquals('essay', $o->getOneVersion(2)->getStyle(), 'Second version is an essay');
}

public function testWithInheritance()
{
$b1 = new \VersionableBehaviorTest8Foo();
$b1->save();

$b1->setFoobar('name');
$b1->save();

$object = $b1->getOneVersion($b1->getVersion());
$this->assertTrue($object instanceof \Versionablebehaviortest8Version);
}
}

0 comments on commit b525135

Please sign in to comment.