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

svn at limb-project.com svn at limb-project.com
Tue Jul 22 14:00:08 MSD 2008


Author: serega
Date: 2008-07-22 14:00:08 +0400 (Tue, 22 Jul 2008)
New Revision: 7126
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7126

Modified:
   3.x/trunk/limb/active_record/src/lmbARQuery.class.php
   3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php
Log:
-- lazy attributes are not loaded while using eager join feature

Modified: 3.x/trunk/limb/active_record/src/lmbARQuery.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARQuery.class.php	2008-07-21 08:57:30 UTC (rev 7125)
+++ 3.x/trunk/limb/active_record/src/lmbARQuery.class.php	2008-07-22 10:00:08 UTC (rev 7126)
@@ -88,7 +88,9 @@
     $rs = parent :: fetch();
 
     if($decorate)
+    {
       $rs = new lmbARRecordSetDecorator($rs, $this->base_class_name, $this->_conn);
+    }
     
     $rs = $this->_decorateWithJoinDecorator($rs);
     

Modified: 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php	2008-07-21 08:57:30 UTC (rev 7125)
+++ 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php	2008-07-22 10:00:08 UTC (rev 7126)
@@ -72,8 +72,13 @@
 
       $fields = new lmbSet();
       $prefix = $this->prefix . $relation_name . '__';
+      
+      if($record instanceof lmbActiveRecord)
+        $data = $record->exportRaw();
+      else
+        $data = $record->export();
 
-      foreach($record->export() as $field => $value)
+      foreach($data as $field => $value)
       {
         if(strpos($field, $prefix) === 0)
         {

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php	2008-07-21 08:57:30 UTC (rev 7125)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php	2008-07-22 10:00:08 UTC (rev 7126)
@@ -7,12 +7,6 @@
  * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 
-class LazyTestOneTableObject extends lmbActiveRecord
-{
-  protected $_db_table_name = 'test_one_table_object';
-  protected $_lazy_attributes = array('annotation', 'content');
-}
-
 class lmbARAttributesLazyLoadingTest extends lmbARBaseTestCase
 {
   protected $tables_to_cleanup = array('test_one_table_object'); 
@@ -35,6 +29,58 @@
     $this->_checkLazyness($object2, $annotation, $content);
   }
 
+  function testLazyWorksOkForEagerJoin_OneToOneRelations()
+  {
+    $person = new PersonForLazyAttributesTest();
+    $person->setName('Some name');
+    
+    $lazy_object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
+    $person->set('lazy_object', $lazy_object);
+
+    $person->save();
+    
+    $person_loaded = lmbActiveRecord :: findOne('PersonForLazyAttributesTest', 
+                                                array('criteria' => 'person_for_test.id = ' . $person->getId(),
+                                                      'join' => 'lazy_object'));
+    
+    $lazy_object2 = $person_loaded->getLazyObject(); 
+    $this->_checkLazyness($lazy_object2, $annotation, $content);
+  }
+  
+  function testLazyWorksOkForEagerJoin_ForParentObject_OneToOneRelations()
+  {
+    $person = new PersonForLazyAttributesTest();
+    $person->setName($name = 'Some name');
+    
+    $lazy_object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
+    $person->set('lazy_object', $lazy_object);
+
+    $person->save();
+    
+    $person_loaded = lmbActiveRecord :: findOne('PersonForLazyAttributesTest', 
+                                                array('criteria' => 'person_for_test.id = ' . $person->getId(),
+                                                      'join' => 'lazy_object'));
+    $this->assertFalse(array_key_exists('name', $person_loaded->exportRaw()));
+  }
+
+  function testLazyWorksOkForEagerAttach_OneToOneRelations()
+  {
+    $person = new PersonForLazyAttributesTest();
+    $person->setName('Some name');
+    
+    $lazy_object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
+    $person->set('lazy_object', $lazy_object);
+
+    $person->save();
+    
+    $person_loaded = lmbActiveRecord :: findOne('PersonForLazyAttributesTest', 
+                                                array('criteria' => 'person_for_test.id = ' . $person->getId(),
+                                                      'attach' => 'lazy_object'));
+    
+    $lazy_object2 = $person_loaded->getLazyObject(); 
+    $this->_checkLazyness($lazy_object2, $annotation, $content);
+  }
+  
   function testExportIsNotLazy()
   {
     $object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php	2008-07-21 08:57:30 UTC (rev 7125)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php	2008-07-22 10:00:08 UTC (rev 7126)
@@ -16,6 +16,12 @@
   }
 }
 
+class LazyTestOneTableObject extends lmbActiveRecord
+{
+  protected $_db_table_name = 'test_one_table_object';
+  protected $_lazy_attributes = array('annotation', 'content');
+}
+
 class PersonForTest extends lmbActiveRecord
 {
   public $save_count = 0;
@@ -29,6 +35,15 @@
   }
 }
 
+class PersonForLazyAttributesTest extends lmbActiveRecord
+{
+  protected $_db_table_name = 'person_for_test';
+  protected $_has_one = array('lazy_object' => array('field' => 'ss_id',
+                                                     'class' => 'LazyTestOneTableObject',
+                                                     'can_be_null' => true));
+  protected $_lazy_attributes = array('name');
+}
+
 class SocialSecurityForTest extends lmbActiveRecord
 {
   protected $_belongs_to = array('person' => array('field' => 'ss_id',



More information about the limb-svn mailing list