diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index e35f804..32435a4 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -167,6 +167,15 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa // foreign key? if ($isARealColumn) { + // self referencing entry + if ($column->isPrimaryKey() && null !== $value) { + if (isset($this->object_references[$class.'_'.$value])) { + $obj = $this->object_references[$class.'_'.$value]; + + continue; + } + } + if ($column->isForeignKey() && null !== $value) { $relatedTable = $this->dbMap->getTable($column->getRelatedTableName()); if (!isset($this->object_references[$relatedTable->getClassname().'_'.$value])) { diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index a15fe0a..f80d80f 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -108,4 +108,31 @@ YAML; $this->assertCount(1, $bookAuthors); $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookAuthor', $bookAuthors[0]); } + + public function testLoadSelfReferencing() + { + $fixtures = <<getTempFile($fixtures); + + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader'); + $loader->load(array($filename), 'default'); + + $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con); + $this->assertCount(0, $books); + + $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthorPeer::doSelect(new \Criteria(), $this->con); + $this->assertCount(1, $authors); + + $author = $authors[0]; + $this->assertEquals('A famous one', $author->getName()); + } }