Browse Source

Reverting changes done to Collection::compile() as it breaks other code

The main reaosn compile exsted was to detach the iterator pointers from one
collection to the other. The solution using another iterator still keeps those
pointers, causing old bugs to re-appear
Jose Lorenzo Rodriguez 11 years ago
parent
commit
8118c7ef92
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/Collection/CollectionTrait.php

+ 6 - 3
src/Collection/CollectionTrait.php

@@ -17,7 +17,6 @@ namespace Cake\Collection;
 use AppendIterator;
 use ArrayObject;
 use Cake\Collection\Collection;
-use Cake\Collection\Iterator\BufferedIterator;
 use Cake\Collection\Iterator\ExtractIterator;
 use Cake\Collection\Iterator\FilterIterator;
 use Cake\Collection\Iterator\InsertIterator;
@@ -880,10 +879,14 @@ trait CollectionTrait {
  * You can think of this method as a way to create save points for complex
  * calculations in a collection.
  *
+ * @param bool $preserveKeys whether to use the keys returned by this
+ * collection as the array keys. Keep in mind that it is valid for iterators
+ * to return the same key for different elements, setting this value to false
+ * can help getting all items if keys are not important in the result.
  * @return \Cake\Collection\Collection
  */
-	public function compile() {
-		return new BufferedIterator($this);
+	public function compile($preserveKeys = true) {
+		return new Collection($this->toArray($preserveKeys));
 	}
 
 /**