Skip to content

Commit

Permalink
Merge pull request #664 from mazenovi/master
Browse files Browse the repository at this point in the history
add an excluded_parent_behavior to concret_inheritance behavior
  • Loading branch information
willdurand committed Apr 17, 2013
2 parents c1d5370 + 5b7878a commit 97013cf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
Expand Up @@ -28,13 +28,15 @@ class ConcreteInheritanceBehavior extends Behavior
'extends' => '',
'descendant_column' => 'descendant_class',
'copy_data_to_parent' => 'true',
'schema' => ''
'schema' => '',
'excluded_parent_behavior' => 'nested_set',
);

public function modifyTable()
{
$table = $this->getTable();
$parentTable = $this->getParentTable();
$excludedParentBehavior = explode(',', $this->parameters['excluded_parent_behavior']);

if ($this->isCopyData()) {
// tell the parent table that it has a descendant
Expand Down Expand Up @@ -104,7 +106,7 @@ public function modifyTable()

// add the Behaviors of the parent table
foreach ($parentTable->getBehaviors() as $behavior) {
if ($behavior->getName() == 'concrete_inheritance_parent' || $behavior->getName() == 'concrete_inheritance') {
if (in_array($behavior->getName(), $excludedParentBehavior) || $behavior->getName() == 'concrete_inheritance_parent' || $behavior->getName() == 'concrete_inheritance') {
continue;
}
$copiedBehavior = clone $behavior;
Expand Down Expand Up @@ -265,4 +267,4 @@ public function getSyncParent(\$con = null)
}
";
}
}
}
Expand Up @@ -4,6 +4,13 @@
<table name="concrete_category">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name" type="VARCHAR" size="100" primaryString="true" />
<behavior name="nested_set" />
</table>

<table name="concrete_tag">
<behavior name="concrete_inheritance">
<parameter name="extends" value="concrete_category" />
</behavior>
</table>

<table name="concrete_content">
Expand Down Expand Up @@ -74,4 +81,4 @@
</foreign-key>
</table>

</database>
</database>
@@ -0,0 +1,39 @@
<?php

/*
* $Id: ConcreteInheritanceBehaviorTest.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/bookstore/BookstoreTestBase.php';

/**
* Tests for ConcreteInheritanceParentBehavior class
*
* @author François Zaniontto
* @version $Revision$
* @package generator.behavior.concrete_inheritance
*/
class ConcreteInheritanceExcludedParentBehaviorTest extends BookstoreTestBase
{
public function testHasChildObjectAddChildMethod()
{

$article = new ConcreteTag(); // to autoload the BaseConcreteArticle class
$r = new ReflectionClass('BaseConcreteTag');
$p =$r->getMethod('addChild')->getParameters();
$this->assertEquals('ConcreteCategory', $p[0]->getClass()->getName(), 'concrete_inheritance does not generate addChild method child object class');
}

public function testHasChildPeerIsValidMethod()
{
$r = new ReflectionClass('BaseConcreteTagPeer');
$p =$r->getMethod('isValid')->getParameters();
$this->assertEquals('ConcreteCategory', $p[0]->getClass()->getName(), 'concrete_inheritance does not generate isValid method child peer class');
}

}

0 comments on commit 97013cf

Please sign in to comment.