Permalink
Browse files

Bail early if Junction table is already instanciated and is not speci…

…fied.
  • Loading branch information...
1 parent 4d96262 commit e3d74c39d7ab3cc638f2400da940b97e73262e1f @bar bar committed Mar 3, 2014
Showing with 14 additions and 14 deletions.
  1. +14 −14 src/ORM/Association/BelongsToMany.php
View
28 src/ORM/Association/BelongsToMany.php
@@ -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)) {

0 comments on commit e3d74c3

Please sign in to comment.