Skip to content

Commit

Permalink
Bail early if Junction table is already instanciated and is not speci…
Browse files Browse the repository at this point in the history
…fied.
  • Loading branch information
bar committed Mar 3, 2014
1 parent 4d96262 commit e3d74c3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -154,22 +154,22 @@ public function junction($table = null) {
$tAlias = $target->alias();

if ($table === null) {
if (empty($this->_junctionTable)) {
if (!empty($this->_through)) {
$table = $this->_through;
} else {
$tableName = $this->_junctionTableName();
$tableAlias = Inflector::camelize($tableName);

$config = [];
if (!TableRegistry::exists($tableAlias)) {
$config = ['table' => $tableName];
}
$table = TableRegistry::get($tableAlias, $config);
}
} else {
if (!empty($this->_junctionTable)) {
return $this->_junctionTable;
}

if (!empty($this->_through)) {
$table = $this->_through;
} else {
$tableName = $this->_junctionTableName();
$tableAlias = Inflector::camelize($tableName);

$config = [];
if (!TableRegistry::exists($tableAlias)) {
$config = ['table' => $tableName];
}
$table = TableRegistry::get($tableAlias, $config);
}
}

if (is_string($table)) {
Expand Down

0 comments on commit e3d74c3

Please sign in to comment.