Commit 102f1068 authored by gnat's avatar gnat

fix class generation of yml schema fully defined m2m relationships.

parent 6b26a7b8
...@@ -189,8 +189,8 @@ class Doctrine_Import_Schema ...@@ -189,8 +189,8 @@ class Doctrine_Import_Schema
$relation['type'] = Doctrine_Relation::ONE; $relation['type'] = Doctrine_Relation::ONE;
} }
if (isset($relation['ftype']) && $relation['ftype']) { if (isset($relation['foreignType']) && $relation['foreignType']) {
$relation['ftype'] = $relation['ftype'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY; $relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
} }
if(isset($relation['refClass']) && !empty($relation['refClass']) && (!isset($array[$relation['refClass']]['relations']) || empty($array[$relation['refClass']]['relations']))) { if(isset($relation['refClass']) && !empty($relation['refClass']) && (!isset($array[$relation['refClass']]['relations']) || empty($array[$relation['refClass']]['relations']))) {
...@@ -212,21 +212,29 @@ class Doctrine_Import_Schema ...@@ -212,21 +212,29 @@ class Doctrine_Import_Schema
// define both sides of the relationship // define both sides of the relationship
foreach($this->relations as $className => $relations) { foreach($this->relations as $className => $relations) {
foreach ($relations AS $alias => $relation) { foreach ($relations AS $alias => $relation) {
if(isset($relation['ignore']) && $relation['ignore'] || isset($relation['refClass'])) if(isset($relation['ignore']) && $relation['ignore'] || isset($relation['refClass']) || isset($this->relations[$relation['class']]['relations'][$className])) {
continue; continue;
}
$newRelation = array(); $newRelation = array();
$newRelation['foreign'] = $relation['local']; $newRelation['foreign'] = $relation['local'];
$newRelation['local'] = $relation['foreign']; $newRelation['local'] = $relation['foreign'];
$newRelation['class'] = $className; $newRelation['class'] = $className;
$newRelation['alias'] = isset($relation['foreignAlias'])?$relation['foreignAlias']:$className; $newRelation['alias'] = isset($relation['foreignAlias'])?$relation['foreignAlias']:$className;
if(isset($relation['ftype'])) { if(isset($relation['foreignType'])) {
$newRelation['type']=$relation['ftype']; $newRelation['type']=$relation['foreignType'];
} else { } else {
$newRelation['type'] = $relation['type'] === Doctrine_Relation::ONE ? Doctrine_Relation::MANY:Doctrine_Relation::ONE; $newRelation['type'] = $relation['type'] === Doctrine_Relation::ONE ? Doctrine_Relation::MANY:Doctrine_Relation::ONE;
} }
$this->relations[$relation['class']][$className] = $newRelation; if( isset($this->relations[$relation['class']]) && is_array($this->relations[$relation['class']]) ) {
foreach($this->relations[$relation['class']] as $otherRelation) {
if(isset($otherRelation['refClass']) && $otherRelation['refClass']==$className) // skip fully defined m2m relationships
return;
}
}
else
$this->relations[$relation['class']][$className] = $newRelation;
} }
} }
} }
......
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