[limb-svn] r6712 - in 3.x/trunk/limb/active_record: src tests/cases

svn at limb-project.com svn at limb-project.com
Mon Jan 21 12:18:22 MSK 2008


Author: serega
Date: 2008-01-21 12:18:22 +0300 (Mon, 21 Jan 2008)
New Revision: 6712
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6712

Modified:
   3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php
Log:
-- now lmbARRecordSetAttachDecorator set an empty collection into active record object with not attached were loaded.

Modified: 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php	2008-01-21 09:11:13 UTC (rev 6711)
+++ 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php	2008-01-21 09:18:22 UTC (rev 6712)
@@ -129,12 +129,10 @@
         break;
         case lmbActiveRecord :: HAS_MANY:
         case lmbActiveRecord :: HAS_MANY_TO_MANY:
+          $collection = $this->base_object->createRelationCollection($relation_name);
           if(isset($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())]))
-          {
-            $collection = $this->base_object->createRelationCollection($relation_name);
             $collection->setDataset(new lmbCollection($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())]));
-            $fields->set($this->prefix . $relation_name, $collection);
-          }
+          $fields->set($this->prefix . $relation_name, $collection);
         break;
       }
     }

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php	2008-01-21 09:11:13 UTC (rev 6711)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php	2008-01-21 09:18:22 UTC (rev 6712)
@@ -635,13 +635,21 @@
     $program1 = $this->creator->createProgram();
     $program2 = $this->creator->createProgram();
     
+    $this->conn->resetStats();
+    
     $query = lmbARQuery :: create('ProgramForTest', array(), $this->conn);
     $arr = $query->attach('courses')->fetch()->getArray();
+
+    $this->assertEqual($this->conn->countQueries(), 2);
+
+    $this->conn->resetStats();
     
     $this->assertEqual($arr[0]->getTitle(), $program1->getTitle());
     $this->assertEqual($arr[1]->getTitle(), $program2->getTitle());
     $this->assertEqual($arr[0]->getCourses()->count(), 0);
     $this->assertEqual($arr[1]->getCourses()->count(), 0);
+
+    $this->assertEqual($this->conn->countQueries(), 0);
   }  
 
   function testFetch_JoinWithWrongRelationType()
@@ -667,14 +675,21 @@
     $course1 = $this->creator->createCourse();
     $course2 = $this->creator->createCourse();
     
+    $this->conn->resetStats();
+    
     $query = lmbARQuery :: create('CourseForTest', array(), $this->conn);
     $arr = $query->attach('program')->fetch()->getArray();
 
+    $this->assertEqual($this->conn->countQueries(), 2);    
+
+    $this->conn->resetStats();
     $this->assertEqual($arr[0]->getTitle(), $course1->getTitle());
     $this->assertEqual($arr[1]->getTitle(), $course2->getTitle());
 
     $this->assertNull($arr[0]->getProgram(), 0);
     $this->assertNull($arr[1]->getProgram(), 0);
+    
+    $this->assertEqual($this->conn->countQueries(), 0);    
   }
 }
 



More information about the limb-svn mailing list