Fixes to model building so it does not generate duplicate relations.
This commit is contained in:
parent
13a79c4595
commit
70addc55ca
@ -212,7 +212,24 @@ class Doctrine_Import_Schema
|
|||||||
*/
|
*/
|
||||||
public function getRelations($properties)
|
public function getRelations($properties)
|
||||||
{
|
{
|
||||||
return isset($this->_relations[$properties['className']]) ? $this->_relations[$properties['className']]:array();
|
$allRelations = isset($this->_relations[$properties['className']]) ? $this->_relations[$properties['className']]:array();
|
||||||
|
|
||||||
|
// This is for checking for duplicates between alias-relations and a auto-generated relations to ensure the result set of unique relations
|
||||||
|
$existingRelations = array();
|
||||||
|
$uniqueRelations = array();
|
||||||
|
foreach ($allRelations as $relation) {
|
||||||
|
if ( ! in_array($relation['key'], $existingRelations)) {
|
||||||
|
$existingRelations[] = $relation['key'];
|
||||||
|
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
|
||||||
|
} else {
|
||||||
|
// check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it
|
||||||
|
if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) {
|
||||||
|
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $uniqueRelations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -376,7 +393,7 @@ class Doctrine_Import_Schema
|
|||||||
* @param string $array
|
* @param string $array
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _buildRelationships(&$array)
|
protected function _buildRelationships($array)
|
||||||
{
|
{
|
||||||
foreach ($array as $name => $properties) {
|
foreach ($array as $name => $properties) {
|
||||||
if ( ! isset($properties['relations'])) {
|
if ( ! isset($properties['relations'])) {
|
||||||
@ -415,6 +432,8 @@ class Doctrine_Import_Schema
|
|||||||
$relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
|
$relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$relation['key'] = $this->_buildUniqueRelationKey($relation);
|
||||||
|
|
||||||
$this->_relations[$className][$alias] = $relation;
|
$this->_relations[$className][$alias] = $relation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,9 +475,21 @@ class Doctrine_Import_Schema
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->_relations[$relation['class']][$newRelation['alias']])) {
|
if (!isset($this->_relations[$relation['class']][$newRelation['alias']])) {
|
||||||
|
$newRelation['key'] = $this->_buildUniqueRelationKey($newRelation);
|
||||||
$this->_relations[$relation['class']][$newRelation['alias']] = $newRelation;
|
$this->_relations[$relation['class']][$newRelation['alias']] = $newRelation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _buildUniqueRelationKey
|
||||||
|
*
|
||||||
|
* @param string $relation
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _buildUniqueRelationKey($relation)
|
||||||
|
{
|
||||||
|
return md5($relation['local'].$relation['foreign'].$relation['class'].(isset($relation['refClass']) ? $relation['refClass']:null));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user