Browse Source

Reset EagerLoader when cloning a query.

When a 'clean' copy is made of a query we need to reset the eager loader
so changes to associations are separate. Make sure to keep the contained
associations around though.

Refs #5961
Mark Story 11 years ago
parent
commit
ee4d309dab
2 changed files with 3 additions and 0 deletions
  1. 1 0
      src/ORM/Query.php
  2. 2 0
      tests/TestCase/ORM/QueryTest.php

+ 1 - 0
src/ORM/Query.php

@@ -479,6 +479,7 @@ class Query extends DatabaseQuery implements JsonSerializable
         $query = clone $this;
         $query->triggerBeforeFind();
         $query->autoFields(false);
+        $query->eagerLoader(clone $this->eagerLoader());
         $query->limit(null);
         $query->order([], true);
         $query->offset(null);

+ 2 - 0
tests/TestCase/ORM/QueryTest.php

@@ -2361,6 +2361,8 @@ class QueryTest extends TestCase
         $copy = $query->cleanCopy();
 
         $this->assertNotSame($copy, $query);
+        $this->assertNotSame($copy->eagerLoader(), $query->eagerLoader());
+        $this->assertNotEmpty($copy->eagerLoader()->contain());
         $this->assertNull($copy->clause('offset'));
         $this->assertNull($copy->clause('limit'));
         $this->assertNull($copy->clause('order'));