Skip to content
Permalink
Browse files

Fixed the remaining failing tests

  • Loading branch information...
lorenzo committed Jun 25, 2016
1 parent 8266851 commit 18ada258472441fa6fc226a6010fbf7607ab5c82
Showing with 19 additions and 16 deletions.
  1. +15 −13 src/ORM/Association/BelongsToMany.php
  2. +4 −3 tests/TestCase/ORM/QueryTest.php
@@ -16,6 +16,7 @@
use Cake\Core\App;
use Cake\Database\ExpressionInterface;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Association;
use Cake\ORM\Query;
@@ -346,7 +347,6 @@ public function attachTo(Query $query, array $options = [])
// Attach the junction table as well we need it to populate _joinData.
$assoc = $this->_targetTable->association($junction->alias());
$query->removeJoin($assoc->name());
$newOptions = array_intersect_key($options, ['joinType' => 1, 'fields' => 1]);
$newOptions += [
'conditions' => $cond,
@@ -371,7 +371,6 @@ protected function _appendNotMatching($query, $options)
if (empty($options['negateMatch'])) {
return;
}
$options += ['conditions' => []];
$junction = $this->junction();
$belongsTo = $junction->association($this->source()->alias());
@@ -389,17 +388,20 @@ protected function _appendNotMatching($query, $options)
]);
$subquery = $this->_appendJunctionJoin($subquery, $conditions);
$query->andWhere(function ($exp) use ($subquery, $conds) {
if (count($conds) === 1) {
return $exp->notIn(key($conds), $subquery);
}
return $this->_createTupleCondition(
$subquery,
array_keys($conds),
$subquery,
'NOT IN'
);
});
$query
->andWhere(function ($exp) use ($subquery, $conds) {
$identifiers = [];
foreach (array_keys($conds) as $field) {
$identifiers = new IdentifierExpression($field);
}
$identifiers = $subquery->newExpr()->add($identifiers)->tieWith(',');
$nullExp = clone $exp;
return $exp
->or_([
$exp->notIn($identifiers, $subquery),
$nullExp->and(array_map([$nullExp, 'isNull'], array_keys($conds))),
]);
});
}
/**
@@ -3029,7 +3029,6 @@ public function testLeftJoinWithSelect()
})
->autoFields(true)
->where(['ArticlesTags.tag_id' => 3])
->distinct(['authors.id'])
->all();
$expected = ['id' => 2, 'title' => 'Second Article'];
@@ -3165,8 +3164,9 @@ public function testNotMatchingBelongsToMany()
->hydrate(false)
->notMatching('tags', function ($q) {
return $q->where(['tags.name' => 'tag2']);
})
->toArray();
});
$results = $results->toArray();
$expected = [
[
@@ -3200,6 +3200,7 @@ public function testNotMatchingDeep()
$results = $table->find()
->hydrate(false)
->select('authors.id')
->notMatching('articles.tags', function ($q) {
return $q->where(['tags.name' => 'tag3']);
})

0 comments on commit 18ada25

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