Skip to content
Permalink
Browse files

Make better use of local variable.

Call target() fewer times when marshalling belongsToMany associations.

Refs #6867
  • Loading branch information...
markstory committed Jun 25, 2015
1 parent 2238303 commit eb4a7b62d85bd7b524d9b77dfcfb6fcd9b9e436c
Showing with 4 additions and 5 deletions.
  1. +4 −5 src/ORM/Marshaller.php
@@ -283,11 +283,10 @@ protected function _belongsToMany(Association $assoc, array $data, $options = []
}
$data = array_values($data);
$primaryKey = array_flip($assoc->target()->schema()->primaryKey());
$records = [];
$conditions = [];
$primaryCount = count($primaryKey);
$target = $assoc->target();
$primaryKey = array_flip($target->schema()->primaryKey());
$records = $conditions = [];
$primaryCount = count($primaryKey);
foreach ($data as $i => $row) {
if (!is_array($row)) {
@@ -306,7 +305,7 @@ protected function _belongsToMany(Association $assoc, array $data, $options = []
}
if (!empty($conditions)) {
$query = $assoc->target()->find();
$query = $target->find();
$query->andWhere(function ($exp) use ($conditions) {
return $exp->or_($conditions);
});

0 comments on commit eb4a7b6

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