Commit 1bbc5b15 authored by Jonathan.Wage's avatar Jonathan.Wage

Fixes to relationship building and added support for new schema options.

parent be20cf3b
......@@ -278,12 +278,16 @@ END;
$build = '';
foreach ($templates as $name => $options) {
if (is_array($options)) {
if (is_array($options) && !empty($options)) {
$optionsPhp = $this->arrayToPhpArrayCode($options);
$build .= "\t\t\$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n";
} else {
if (isset($templates[0])) {
$build .= "\t\t\$this->loadTemplate('" . $options . "');\n";
} else {
$build .= "\t\t\$this->loadTemplate('" . $name . "');\n";
}
}
}
......@@ -294,40 +298,30 @@ END;
{
$build = '';
foreach ($actAs as $name => $options) {
$optionsPhp = $this->arrayToPhpArrayCode($options);
if (is_array($options) && !empty($options)) {
$optionsPhp = $this->arrayToPhp($options);
$build .= "\t\t\$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
}
return $build;
}
protected function arrayToPhpArrayCode($array)
{
$build = 'array(';
foreach ($array as $key => $value) {
if (is_array($value)) {
$build .= $this->arrayToPhpArrayCode($value);
} else {
$build .= "'" . $key . "' => ";
if (is_integer($value)) {
$build .= "$value";
} else if (is_string($value)) {
$build .= "'" . $value . "'";
} else if (is_bool($value)) {
$build .= $value ? "true":"false";
if (isset($actAs[0])) {
$build .= "\t\t\$this->actAs('" . $options . "');\n";
} else {
$build .= "\t\t\$this->actAs('" . $name . "');\n";
}
$build .= ", ";
}
}
$build = substr($build, 0, strlen($build) - 2);
return $build;
}
$build .= ')';
protected function arrayToPhp(array $array)
{
ob_start();
var_export($array);
$php = ob_get_contents();
ob_end_clean();
return $build;
return $php;
}
public function buildAttributes(array $attributes)
......
......@@ -298,14 +298,24 @@ class Doctrine_Import_Schema
$relations = $properties['relations'];
foreach ($relations as $alias => $relation) {
$class = isset($relation['class']) ? $relation['class']:$alias;
// Attempt to guess the local and foreign
if (isset($relation['refClass'])) {
$relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($name) . '_id';
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:Doctrine::tableize($class) . '_id';
} else {
$relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($class) . '_id';
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id';
}
$relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias;
$relation['class'] = $class;
if (isset($relation['refClass'])) {
$relation['type'] = 'many';
}
if (isset($relation['type']) && $relation['type']) {
$relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
} else {
......@@ -317,8 +327,26 @@ class Doctrine_Import_Schema
}
if(isset($relation['refClass']) && !empty($relation['refClass']) && (!isset($array[$relation['refClass']]['relations']) || empty($array[$relation['refClass']]['relations']))) {
$array[$relation['refClass']]['relations'][$className] = array('local' => $relation['local'], 'foreign' => $relation['foreign'], 'ignore' => true);
$array[$relation['refClass']]['relations'][$relation['class']] = array('local' => $relation['local'], 'foreign' => $relation['foreign'], 'ignore' => true);
if (!isset($array[$relation['refClass']]['relations'][$className]['local'])) {
$array[$relation['refClass']]['relations'][$className]['local'] = $relation['local'];
}
if (!isset($array[$relation['refClass']]['relations'][$className]['foreign'])) {
$array[$relation['refClass']]['relations'][$className]['foreign'] = $relation['foreign'];
}
$array[$relation['refClass']]['relations'][$className]['ignore'] = true;
if (!isset($array[$relation['refClass']]['relations'][$relation['class']]['local'])) {
$array[$relation['refClass']]['relations'][$relation['class']]['local'] = $relation['local'];
}
if (!isset($array[$relation['refClass']]['relations'][$relation['class']]['foreign'])) {
$array[$relation['refClass']]['relations'][$relation['class']]['foreign'] = $relation['foreign'];
}
$array[$relation['refClass']]['relations'][$relation['class']]['ignore'] = true;
if(isset($relation['foreignAlias'])) {
$array[$relation['class']]['relations'][$relation['foreignAlias']] = array('type'=>$relation['type'],'local'=>$relation['foreign'],'foreign'=>$relation['local'],'refClass'=>$relation['refClass'],'class'=>$className);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment