Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add support for delegated fixtures in 1:1 relation #223

Merged
merged 1 commit into from

2 participants

@havvg
Collaborator

No description provided.

@willdurand willdurand merged commit 4b9747d into propelorm:1.2

1 check passed

Details default The Travis build passed
@willdurand
Owner

Thanks! Don't hesitate to tag new versions BTW

@havvg
Collaborator

I will, just wanted to for propelorm/Propel#647, because I needed both :)

@havvg havvg deleted the havvg:feature/data-loader-fkpk branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @havvg
This page is out of date. Refresh to see the latest.
View
7 DataFixtures/Loader/AbstractDataLoader.php
@@ -198,8 +198,11 @@ protected function loadDataFromArray($data = null)
// foreign key?
if ($isARealColumn) {
- // self referencing entry
- if ($column->isPrimaryKey() && null !== $value) {
+ /*
+ * A column, which is a PrimaryKey (self referencing, e.g. versionable behavior),
+ * but which is not a ForeignKey (e.g. delegatable behavior on 1:1 relation).
+ */
+ if ($column->isPrimaryKey() && null !== $value && !$column->isForeignKey()) {
if (isset($this->object_references[$class.'_'.$value])) {
$obj = $this->object_references[$class.'_'.$value];
View
52 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
@@ -411,4 +411,56 @@ public function testLoadArrayToObjectType()
$this->assertInstanceOf('\Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObject', $book);
$this->assertEquals(array('opt1' => 2012, 'opt2' => 140, 'inner' => array('subOpt' => 123)), $book->getOptions());
}
+
+ public function testLoadDelegatedOnPrimaryKey()
+ {
+ $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="yaml_delegate_on_primary_key_person" phpName="YamlDelegateOnPrimaryKeyPerson">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
+ <column name="name" type="varchar" size="255" />
+ </table>
+
+ <table name="yaml_delegate_on_primary_key_author" phpName="YamlDelegateOnPrimaryKeyAuthor">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="false" />
+ <column name="count_books" type="integer" defaultValue="0" required="true" />
+
+ <behavior name="delegate">
+ <parameter name="to" value="yaml_delegate_on_primary_key_person" />
+ </behavior>
+
+ <foreign-key foreignTable="yaml_delegate_on_primary_key_person" onDelete="RESTRICT" onUpdate="CASCADE">
+ <reference local="id" foreign="id" />
+ </foreign-key>
+ </table>
+</database>
+XML;
+
+ $fixtures = <<<YAML
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyPerson:
+ yaml_delegate_on_primary_key_person_1:
+ name: "Some Persons Name"
+
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyAuthor:
+ yaml_delegate_on_primary_key_author_1:
+ id: yaml_delegate_on_primary_key_person_1
+ count_books: 7
+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\YamlDelegateOnPrimaryKeyAuthorPeer::doSelect(new \Criteria(), $con);
+ $this->assertCount(1, $authors);
+
+ $author = $authors[0];
+ $person = $author->getYamlDelegateOnPrimaryKeyPerson();
+ $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyPerson', $person);
+ }
}
Something went wrong with that request. Please try again.