Skip to content

Commit

Permalink
Merge pull request #569 from nibsirahsieu/fix_set_descendant_class
Browse files Browse the repository at this point in the history
fix set descendant class
  • Loading branch information
willdurand committed Jan 24, 2013
2 parents f7c9834 + dcfd0cc commit 68dcfce
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function getParentOrCreate(\$con = null)
if (null === \$parent || null !== \$parent->getDescendantClass()) {
\$parent = new " . $parentClass . "();
\$parent->setPrimaryKey(\$this->getPrimaryKey());
\$parent->set" . $this->getParentTable()->getColumn($this->getParameter('descendant_column'))->getPhpName() . "('" . $this->builder->getStubObjectBuilder()->getClassname() . "');
\$parent->set" . $this->getParentTable()->getColumn($this->getParameter('descendant_column'))->getPhpName() . "('" . $this->builder->getStubObjectBuilder()->getFullyQualifiedClassname() . "');
}
return \$parent;
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/namespaced/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,16 @@
<reference local="supervisor_id" foreign="id" />
</foreign-key>
</table>

<table name="ns_concrete_content" phpName="NamespacedConcreteContent" namespace="Foo\Bar">
<column name="id" required="true" primaryKey="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" primaryString="true" />
</table>

<table name="ns_concrete_article" phpName="NamespacedConcreteArticle" namespace="Foo\Bar">
<column name="body" type="longvarchar" />
<behavior name="concrete_inheritance">
<parameter name="extends" value="ns_concrete_content" />
</behavior>
</table>
</database>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* $Id: ConcreteInheritanceBehaviorNamespacedTest.php 1458 2010-01-13 16:09:51Z francois $
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

require_once dirname(__FILE__) . '/../../../../tools/helpers/namespaces/NamespacesTestBase.php';

/**
* Tests for ConcreteInheritanceBehaviorNamespacedTest class
*
* @author François Zaniontto
* @version $Revision$
* @package generator.behavior.concrete_inheritance
*/
class ConcreteInheritanceBehaviorNamespacedTest extends NamespacesTestBase
{
public function testgetParentOrCreateWithPrimaryKeyIsNull()
{
$concreteArticle = new \Foo\Bar\NamespacedConcreteArticle();
$concreteArticle->setTitle('Foo');
$concreteArticle->setBody('Bar');
$parent = $concreteArticle->getParentOrCreate();
$this->assertEquals('Foo\Bar\NamespacedConcreteArticle', $parent->getDescendantClass(), 'getDescendantClass() will return Foo\Bar\NamespacedConcreteArticle');
}

public function testgetParentOrCreateWithPrimaryKeyNotNull()
{
$concreteArticle = new \Foo\Bar\NamespacedConcreteArticle();
$concreteArticle->setPrimaryKey(1);
$concreteArticle->setTitle('Foo');
$concreteArticle->setBody('Bar');
$parent = $concreteArticle->getParentOrCreate();
$this->assertEquals('Foo\Bar\NamespacedConcreteArticle', $parent->getDescendantClass(), 'getDescendantClass() will return Foo\Bar\NamespacedConcreteArticle');
}
}

0 comments on commit 68dcfce

Please sign in to comment.