Merge pull request #110 from havvg/hotfix/dataloader-array-column
add handling of array type in data loader
This commit is contained in:
commit
c4459e665e
|
@ -150,6 +150,11 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
|
|||
}
|
||||
}
|
||||
elseif (!$isPrimaryKey || ($isPrimaryKey && !$tableMap->isUseIdGenerator())) {
|
||||
if (!empty($row[$col]) && 'ARRAY' === $column->getType()) {
|
||||
$serialized = substr($row[$col], 2, -2);
|
||||
$row[$col] = $serialized ? explode(' | ', $serialized) : array();
|
||||
}
|
||||
|
||||
// We did not want auto incremented primary keys
|
||||
$values[$col] = $row[$col];
|
||||
}
|
||||
|
|
|
@ -161,10 +161,19 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa
|
|||
}
|
||||
|
||||
foreach ($data as $name => $value) {
|
||||
if (is_array($value) && 's' == substr($name, -1)) {
|
||||
// many to many relationship
|
||||
$this->loadManyToMany($obj, substr($name, 0, -1), $value);
|
||||
continue;
|
||||
try {
|
||||
if (is_array($value) && 's' === substr($name, -1)) {
|
||||
// many to many relationship
|
||||
$this->loadManyToMany($obj, substr($name, 0, -1), $value);
|
||||
continue;
|
||||
}
|
||||
} 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()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$isARealColumn = true;
|
||||
|
|
|
@ -25,16 +25,18 @@ class YamlDataDumperTest extends TestCase
|
|||
fb1:
|
||||
Id: 10
|
||||
Title: Hello
|
||||
Tags: null
|
||||
fb2:
|
||||
Id: 20
|
||||
Title: World
|
||||
Tags: [foo, bar, baz]
|
||||
|
||||
YML;
|
||||
|
||||
$array = array(
|
||||
'\Foo\Bar' => array(
|
||||
'fb1' => array('Id' => 10, 'Title' => 'Hello'),
|
||||
'fb2' => array('Id' => 20, 'Title' => 'World')
|
||||
'fb1' => array('Id' => 10, 'Title' => 'Hello', 'Tags' => null),
|
||||
'fb2' => array('Id' => 20, 'Title' => 'World', 'Tags' => array('foo', 'bar', 'baz'))
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@ class YamlDataLoaderTest extends TestCase
|
|||
fb1:
|
||||
Id: 10
|
||||
Title: Hello
|
||||
Tags: null
|
||||
fb2:
|
||||
Id: 20
|
||||
Title: World
|
||||
Tags: [foo, bar, baz]
|
||||
YML;
|
||||
$this->tmpfile = (string) tmpfile();
|
||||
file_put_contents($this->tmpfile, $fixtures);
|
||||
|
@ -54,6 +56,8 @@ YML;
|
|||
$this->assertEquals(2, count($subarray), 'There is two fixtures objects');
|
||||
$this->assertArrayHasKey('fb1', $subarray);
|
||||
$this->assertArrayHasKey('fb2', $subarray);
|
||||
$this->assertTrue(is_array($subarray['fb2']['Tags']));
|
||||
$this->assertEquals(array('foo', 'bar', 'baz'), $subarray['fb2']['Tags']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue