Skip to content
Permalink
Browse files

Remove offset from cloned queries used in subquery loads.

Having an offset in a subquery causes SQL errors in MySQL. Also
include a test to ensure HAVING is not an issue.

Fixes #4465
  • Loading branch information...
markstory committed Sep 3, 2014
1 parent 0368cbd commit 89a56a4db3ca5e4fa539b987bb2c37dcd58e2240
Showing with 21 additions and 1 deletion.
  1. +1 −0 src/ORM/Association/SelectableAssociationTrait.php
  2. +20 −1 tests/TestCase/ORM/QueryRegressionTest.php
@@ -161,6 +161,7 @@ protected function _addFilteringCondition($query, $key, $filter) {
protected function _buildSubquery($query) {
$filterQuery = clone $query;
$filterQuery->limit(null);
$filterQuery->offset(null);
$filterQuery->order([], true);
$filterQuery->contain([], true);
$joins = $filterQuery->join();
@@ -39,7 +39,8 @@ class QueryRegressionTest extends TestCase {
'core.tag',
'core.articles_tag',
'core.author',
'core.special_tag'
'core.special_tag',
'core.translate',
];
/**
@@ -405,4 +406,22 @@ public function testAssociationChainOrder() {
$this->assertNotEmpty($resultA->articles_tag->author);
}
/**
* Test that offset/limit are elided from subquery loads.
*
* @return void
*/
public function testAssociationSubQueryNoOffset() {
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->locale('eng');
$query = $table->find('translations')->limit(10)->offset(1);
$result = $query->toArray();
$this->assertCount(2, $result);
$query = $table->find('translations')->having(['Articles.id >' => 1]);
$result = $query->toArray();
$this->assertCount(2, $result);
}
}

0 comments on commit 89a56a4

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