File tree Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -160,11 +160,8 @@ protected abstract function _linkField($options);
160
160
*/
161
161
protected function _buildSubquery ($ query ) {
162
162
$ filterQuery = clone $ query ;
163
- $ filterQuery ->autoFields (false );
164
- $ filterQuery ->limit (null );
165
- $ filterQuery ->offset (null );
166
- $ filterQuery ->order ([], true );
167
- $ filterQuery ->contain ([], true );
163
+ $ filterQuery ->clear ();
164
+
168
165
$ joins = $ filterQuery ->join ();
169
166
foreach ($ joins as $ i => $ join ) {
170
167
if (strtolower ($ join ['type ' ]) !== 'inner ' ) {
Original file line number Diff line number Diff line change @@ -467,19 +467,38 @@ public function applyOptions(array $options) {
467
467
return $ this ;
468
468
}
469
469
470
+ /**
471
+ * Clear many the clauses that will make cloned queries behave incorrectly.
472
+ *
473
+ * The following clauses/features will be cleared:
474
+ *
475
+ * - autoFields
476
+ * - limit
477
+ * - offset
478
+ * - map/reduce functions
479
+ * - result formatters
480
+ * - order
481
+ * - containments
482
+ */
483
+ public function clear () {
484
+ $ this ->autoFields (false );
485
+ $ this ->limit (null );
486
+ $ this ->order ([], true );
487
+ $ this ->offset (null );
488
+ $ this ->mapReduce (null , null , true );
489
+ $ this ->formatResults (null , true );
490
+ $ this ->contain ([], true );
491
+ }
492
+
470
493
/**
471
494
* Returns the COUNT(*) for the query.
472
495
*
473
496
* @return int
474
497
*/
475
498
public function count () {
476
499
$ query = clone $ this ;
477
- $ query ->autoFields (false );
478
- $ query ->limit (null );
479
- $ query ->order ([], true );
480
- $ query ->offset (null );
481
- $ query ->mapReduce (null , null , true );
482
- $ query ->formatResults (null , true );
500
+ $ query ->clear ();
501
+
483
502
$ counter = $ this ->_counter ;
484
503
485
504
if ($ counter ) {
You can’t perform that action at this time.
0 commit comments