Merge pull request #199 from pixel-cookers/fix-load-fixture-object
[fixtures] allow loading array to object column
This commit is contained in:
commit
cc1a2dc8bc
|
@ -178,7 +178,7 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa
|
|||
} catch (PropelException $e) {
|
||||
// Check whether this is actually an array stored in the object.
|
||||
if ('Cannot fetch TableMap for undefined table: '.substr($name, 0, -1) === $e->getMessage()) {
|
||||
if ('ARRAY' !== $tableMap->getColumn($name)->getType()) {
|
||||
if ('ARRAY' !== $tableMap->getColumn($name)->getType() && 'OBJECT' !== $tableMap->getColumn($name)->getType()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -378,4 +378,37 @@ YAML;
|
|||
$author = $book->getAuthor();
|
||||
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipAuthor', $author);
|
||||
}
|
||||
|
||||
public function testLoadArrayToObjectType()
|
||||
{
|
||||
$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_with_object" phpName="YamlBookWithObject">
|
||||
<column name="id" type="integer" primaryKey="true" />
|
||||
<column name="name" type="varchar" size="255" />
|
||||
<column name="options" type="object" />
|
||||
</table>
|
||||
</database>
|
||||
XML;
|
||||
$fixtures = <<<YAML
|
||||
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObject:
|
||||
book1:
|
||||
name: my book
|
||||
options: {opt1: 2012, opt2: 140, inner: {subOpt: 123}}
|
||||
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');
|
||||
|
||||
$book = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObjectQuery::create(null, $con)->findOne();
|
||||
|
||||
$this->assertInstanceOf('\Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObject', $book);
|
||||
$this->assertEquals(array('opt1' => 2012, 'opt2' => 140, 'inner' => array('subOpt' => 123)), $book->getOptions());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue