1
0
mirror of synced 2025-02-20 06:03:15 +03:00

New fix for the check for duplicates between explicitly declared custom relations and autogenerated relations.

This commit is contained in:
phuson 2007-10-29 05:47:50 +00:00
parent 53eb2ea087
commit ff7aac8b30

View File

@ -210,7 +210,24 @@ class Doctrine_Import_Schema
*/
public function getRelations($properties)
{
return isset($this->_relations[$properties['className']]) ? $this->_relations[$properties['className']]:array();
$all_relations = 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
$exist_relations = array();
$unique_relations = array();
foreach ($all_relations as $relation) {
if (!in_array($relation['class'], $exist_relations)) {
$exist_relations[] = $relation['class'];
$unique_relations = array_merge($unique_relations, 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) {
$unique_relations = array_merge($unique_relations, array($relation['alias'] => $relation));
}
}
}
return $unique_relations;
}
/**
@ -421,6 +438,10 @@ class Doctrine_Import_Schema
$newRelation['class'] = isset($relation['foreignClass']) ? $relation['foreignClass']:$className;
$newRelation['alias'] = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$className;
// this is so that we know that this relation was autogenerated and
// that we do not need to include it if it is explicitly declared in the schema by the users.
$newRelation['autogenerated'] = true;
if (isset($relation['refClass'])) {
$newRelation['refClass'] = $relation['refClass'];
$newRelation['type'] = isset($relation['foreignType']) ? $relation['foreignType']:$relation['type'];