Skip to content
Permalink
Browse files

Call fewer methods when building belongsToMany associations.

Don't call methods more than once when we know the answer already.
  • Loading branch information...
markstory committed Nov 25, 2013
1 parent 6a4dad2 commit 2931b7d2535719e5e823f0d1214f2bcc53f534a7
Showing with 6 additions and 5 deletions.
  1. +6 −5 Cake/ORM/Association/BelongsToMany.php
@@ -106,22 +106,23 @@ public function pivot($table = null) {
if (is_string($table)) {
$table = TableRegistry::get($table);
}
$pivotAlias = $table->alias();
if (!$table->association($sAlias)) {
$table->belongsTo($sAlias)->target($this->source());
$table->belongsTo($sAlias)->target($source);
}
if (!$table->association($tAlias)) {
$table->belongsTo($tAlias)->target($this->target());
$table->belongsTo($tAlias)->target($target);
}
if (!$target->association($table->alias())) {
if (!$target->association($pivotAlias)) {
$target->belongsToMany($sAlias);
$target->hasMany($table->alias())->target($table);
$target->hasMany($pivotAlias)->target($table);
}
if (!$source->association($table->alias())) {
$source->hasMany($table->alias())->target($table);
$source->hasMany($pivotAlias)->target($table);
}
return $this->_pivotTable = $table;

0 comments on commit 2931b7d

Please sign in to comment.
You can’t perform that action at this time.