Skip to content
Permalink
Browse files

Rename clear() to cleanCopy().

It fixes an awkward name and makes the cloning part of the function
which I feel is cleaner and easier to use.
  • Loading branch information...
markstory committed Sep 4, 2014
1 parent 13b224c commit a0bb9050ed50a1c0758147cfa4bc360c30209de5
Showing with 18 additions and 15 deletions.
  1. +1 −2 src/ORM/Association/SelectableAssociationTrait.php
  2. +17 −13 src/ORM/Query.php
@@ -159,8 +159,7 @@ protected function _addFilteringCondition($query, $key, $filter) {
* @return \Cake\ORM\Query
*/
protected function _buildSubquery($query) {
$filterQuery = clone $query;
$filterQuery->clear();
$filterQuery = $query->cleanCopy();
$joins = $filterQuery->join();
foreach ($joins as $i => $join) {
@@ -468,9 +468,9 @@ public function applyOptions(array $options) {
}
/**
* Clear many the clauses that will make cloned queries behave incorrectly.
* Creates a copy of this current query and resets some state.
*
* The following clauses/features will be cleared:
* The following state will be cleared:
*
* - autoFields
* - limit
@@ -479,15 +479,21 @@ public function applyOptions(array $options) {
* - result formatters
* - order
* - containments
*
* This method creates query clones that are useful when working with subqueries.
*
* @return \Cake\ORM\Query
*/
public function clear() {
$this->autoFields(false);
$this->limit(null);
$this->order([], true);
$this->offset(null);
$this->mapReduce(null, null, true);
$this->formatResults(null, true);
$this->contain([], true);
public function cleanCopy() {
$query = clone $this;
$query->autoFields(false);
$query->limit(null);
$query->order([], true);
$query->offset(null);
$query->mapReduce(null, null, true);
$query->formatResults(null, true);
$query->contain([], true);
return $query;
}
/**
@@ -496,9 +502,7 @@ public function clear() {
* @return int
*/
public function count() {
$query = clone $this;
$query->clear();
$query = $this->cleanCopy();
$counter = $this->_counter;
if ($counter) {

0 comments on commit a0bb905

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