1
0
mirror of synced 2025-01-17 22:11:41 +03:00

Fix for importing.

This commit is contained in:
Jonathan.Wage 2007-10-08 22:47:59 +00:00
parent 8c413b2427
commit 94bf9a4c7c
3 changed files with 37 additions and 20 deletions

View File

@ -140,6 +140,17 @@ class Doctrine_Data_Export extends Doctrine_Data
continue;
}
// skip single primary keys, we need to maintain composite primary keys
$keys = $record->getTable()->getIdentifier();
if (!is_array($keys)) {
$keys = array($keys);
}
if (count($keys) <= 1 && in_array($key, $keys)) {
continue;
}
if ($relation = $this->isRelation($record, $key)) {
$relationAlias = $relation['alias'];
$relationRecord = $record->$relationAlias;
@ -160,18 +171,7 @@ class Doctrine_Data_Export extends Doctrine_Data
$relationValue = $relationClassName . '_' . $value;
$preparedData[$className][$recordKey][$relationClassName] = $relationValue;
} else {
// skip single primary keys, we need to maintain composite primary keys
$keys = $record->getTable()->getIdentifier();
if (!is_array($keys)) {
$keys = array($keys);
}
if (count($keys) <= 1 && in_array($key, $keys)) {
continue;
}
} else {
$preparedData[$className][$recordKey][$key] = $value;
}
}

View File

@ -193,7 +193,7 @@ END;
}
if (!empty($ret)) {
return "\n\t\tpublic function setTableDefinition()"."\n\t\t{\n".implode("\n", $ret)."\n\t\t}";
return "\n\tpublic function setTableDefinition()"."\n\t{\n".implode("\n", $ret)."\n\t}";
}
}
public function buildSetUp(array $options, array $columns, array $relations)
@ -264,7 +264,7 @@ END;
}
if (!empty($ret)) {
return "\n\t\tpublic function setUp()\n\t\t{\n".implode("\n", $ret)."\n\t\t}";
return "\n\tpublic function setUp()\n\t{\n".implode("\n", $ret)."\n\t}";
}
}
@ -311,11 +311,14 @@ END;
if ($this->generateBaseClasses()) {
// We only want to generate this one if it doesn't already exist
if (!file_exists($options['fileName'])) {
if (file_exists($options['fileName'])) {
$optionsBak = $options;
unset($options['tableName']);
$options['inheritance']['extends'] = 'Base' . $options['className'];
$options['requires'] = array($this->baseClassesDirectory . DIRECTORY_SEPARATOR . $options['inheritance']['extends'] . $this->suffix);
$options['no_definition'] = true;
$this->writeDefinition($options, array(), array());
$options = $optionsBak;
@ -341,7 +344,21 @@ END;
{
$content = $this->buildDefinition($options, $columns, $relations);
$bytes = file_put_contents($options['fileName'], '<?php' . PHP_EOL . $content);
$code = "<?php\n";
if (isset($options['requires'])) {
if (!is_array($options['requires'])) {
$options['requires'] = array($options['requires']);
}
foreach ($options['requires'] as $require) {
$code .= "require_once('".$require."');";
}
}
$code .= PHP_EOL . $content;
$bytes = file_put_contents($options['fileName'], $code);
if ($bytes === false) {
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $options['fileName']);

View File

@ -4,9 +4,9 @@ require_once('playground.php');
$dbh = new PDO('mysql:host=localhost;dbname=test', 'jwage', 'elite1baller');
$conn = Doctrine_Manager::connection($dbh);
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
//Doctrine::loadModels('test_models');
Doctrine::loadModels('test_models');
$import = new Doctrine_Import_Schema();
$import->generateBaseClasses(true);
$import->importSchema('schema.yml', 'yml', 'test_models');
$data = new Doctrine_Data();
$data->importData('fixtures.yml');