Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: Survos/PropelBundle
base: ef95bcd63c
...
head fork: Survos/PropelBundle
compare: 2e54427376
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
25 DataFixtures/Loader/AbstractDataLoader.php
View
@@ -257,8 +257,7 @@ protected function saveParentReference($class, $key, &$obj)
$reflectionClass = new \ReflectionClass($parentClass);
if (!$reflectionClass->isAbstract()) {
- $parentObj = new $parentClass;
- $parentObj->fromArray($obj->toArray());
+ $parentObj = $obj->getParentOrCreate();
$this->saveParentReference($parentClass, $key, $parentObj);
}
@@ -268,6 +267,24 @@ protected function saveParentReference($class, $key, &$obj)
}
/**
+ * Retrieve all the parent classes of a given class (for the inheritance).
+ *
+ * @param string $class Class name of the current object
+ */
+ protected function getInheritedClasses($class) {
+ $reflectionClass = new \ReflectionClass($class);
+ $classes = array();
+
+ while (!$reflectionClass->isAbstract()) {
+ $classes[] = constant(constant($class.'::PEER').'::TABLE_NAME');
+ $class = get_parent_class(get_parent_class($class));
+ $reflectionClass = new \ReflectionClass($class);
+ }
+
+ return $classes;
+ }
+
+ /**
* Loads many to many objects.
*
* @param BaseObject $obj A Propel object
@@ -278,11 +295,11 @@ protected function loadManyToMany($obj, $middleTableName, $values)
{
$middleTable = $this->dbMap->getTable($middleTableName);
$middleClass = $middleTable->getClassname();
- $tableName = constant(constant(get_class($obj).'::PEER').'::TABLE_NAME');
+ $inheritedClasses = $this->getInheritedClasses(get_class($obj));
foreach ($middleTable->getColumns() as $column) {
if ($column->isForeignKey()) {
- if ($tableName !== $column->getRelatedTableName()) {
+ if (!in_array($column->getRelatedTableName(), $inheritedClasses)) {
$relatedClass = $this->dbMap->getTable($column->getRelatedTableName())->getClassname();
$relatedSetter = 'set' . $column->getRelation()->getName();
} else {
75 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
View
@@ -379,6 +379,81 @@ public function testLoadWithInheritedRelationship()
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipAuthor', $author);
}
+ public function testLoadWithInheritedManyToManyRelationship()
+ {
+ $schema = <<<XML
+<database name="default" package="vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader" defaultIdMethod="native">
+
+ <table name="table_book_inherited_m2m_relationship" phpName="YamlInheritedM2MRelationshipBook">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
+ <column name="name" type="varchar" size="255" />
+ </table>
+
+ <table name="table_history_book_inherited_m2m_relationship" phpName="YamlInheritedM2MRelationshipHistoryBook">
+ <behavior name="concrete_inheritance">
+ <parameter name="extends" value="table_book_inherited_m2m_relationship" />
+ </behavior>
+ </table>
+
+ <table name="table_author_inherited_m2m_relationship" phpName="YamlInheritedM2MRelationshipAuthor">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
+ <column name="name" type="varchar" size="255" />
+ </table>
+
+ <table name="table_nobelized_author_inherited_m2m_relationship" phpName="YamlInheritedM2MRelationshipNobelizedAuthor">
+ <column name="nobel_year" type="integer" />
+ <behavior name="concrete_inheritance">
+ <parameter name="extends" value="table_author_inherited_m2m_relationship" />
+ </behavior>
+ </table>
+
+ <table name="table_book_author_inherited_m2m_relationship" phpName="YamlInheritedM2MRelationshipBookAuthor" isCrossRef="true">
+ <column name="author_id" type="integer" primaryKey="true" />
+ <column name="book_id" type="integer" primaryKey="true" />
+ <foreign-key foreignTable="table_author_inherited_m2m_relationship" phpName="Author">
+ <reference local="author_id" foreign="id" />
+ </foreign-key>
+ <foreign-key foreignTable="table_book_inherited_m2m_relationship" phpName="Book">
+ <reference local="book_id" foreign="id" />
+ </foreign-key>
+ </table>
+
+</database>
+XML;
+
+ $fixtures = <<<YAML
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedM2MRelationshipBook:
+ Book_1:
+ name: 'Supplice du santal'
+
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedM2MRelationshipHistoryBook:
+ Book_2:
+ name: 'Qiushui'
+
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedM2MRelationshipNobelizedAuthor:
+ NobelizedAuthor_1:
+ nobel_year: 2012
+ table_book_author_inherited_m2m_relationships: [Book_1, Book_2]
+
+YAML;
+
+ $filename = $this->getTempFile($fixtures);
+
+ $builder = new \PropelQuickBuilder();
+ $builder->setSchema($schema);
+ $con = $builder->build();
+
+ $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
+ $loader->load(array($filename), 'default');
+
+ $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedM2MRelationshipNobelizedAuthorPeer::doSelect(new \Criteria(), $con);
+ $this->assertCount(1, $authors);
+
+ $author = $authors[0];
+ $books = $author->getBooks();
+ $this->assertCount(2, $books);
+ }
+
public function testLoadArrayToObjectType()
{
$schema = <<<XML

No commit comments for this range

Something went wrong with that request. Please try again.