Commit ca775fdc authored by zYne's avatar zYne

fixed many-to-many column guessing

parent 115cadb0
...@@ -191,22 +191,39 @@ class Doctrine_Relation_Parser ...@@ -191,22 +191,39 @@ class Doctrine_Relation_Parser
$def['table'] = $conn->getTable($def['class']); $def['table'] = $conn->getTable($def['class']);
$def['refTable'] = $conn->getTable($def['refClass']); $def['refTable'] = $conn->getTable($def['refClass']);
if ( ! isset($def['foreign'])) { $id = $def['refTable']->getIdentifier();
// foreign key not set
// try to guess the foreign key
$columns = $this->getIdentifiers($def['table']); if (count($id) > 1) {
if ( ! isset($def['foreign'])) {
$def['foreign'] = $columns; // foreign key not set
} // try to guess the foreign key
if ( ! isset($def['local'])) {
// local key not set $def['foreign'] = ($def['local'] === $id[0]) ? $id[1] : $id[0];
// try to guess the local key }
$columns = $this->getIdentifiers($this->_table); if ( ! isset($def['local'])) {
// foreign key not set
// try to guess the foreign key
$def['local'] = $columns; $def['local'] = ($def['foreign'] === $id[0]) ? $id[1] : $id[0];
} }
} else {
if ( ! isset($def['foreign'])) {
// foreign key not set
// try to guess the foreign key
$columns = $this->getIdentifiers($def['table']);
$def['foreign'] = $columns;
}
if ( ! isset($def['local'])) {
// local key not set
// try to guess the local key
$columns = $this->getIdentifiers($this->_table);
$def['local'] = $columns;
}
}
return $def; return $def;
} }
/** /**
......
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