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

svn at limb-project.com svn at limb-project.com
Tue Jul 22 16:32:13 MSD 2008


Author: serega
Date: 2008-07-22 16:32:13 +0400 (Tue, 22 Jul 2008)
New Revision: 7128
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7128

Modified:
   3.x/trunk/limb/active_record/src/lmbARQuery.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php
Log:
-- improved "with_lazy_attributes" magic param functionality. See lmbARAttributesLazyLoadingTest

Modified: 3.x/trunk/limb/active_record/src/lmbARQuery.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARQuery.class.php	2008-07-22 11:55:02 UTC (rev 7127)
+++ 3.x/trunk/limb/active_record/src/lmbARQuery.class.php	2008-07-22 12:32:13 UTC (rev 7128)
@@ -61,12 +61,16 @@
   
   protected function _addFieldsForObject($object, $table_name = '', $prefix = '', $magic_params = array())
   {
-    $lazy_attributes = array(); 
-    if(!isset($magic_params['with_lazy_attributes']))
-      $lazy_attributes = $object->getLazyAttributes();
-    elseif(is_array($magic_params['with_lazy_attributes']))
-      $lazy_attributes = $magic_params['with_lazy_attributes'];
+    $lazy_attributes = $object->getLazyAttributes();
     
+    if(isset($magic_params['with_lazy_attributes']))
+    {
+      if(!is_array($magic_params['with_lazy_attributes']))
+        $lazy_attributes = array();
+      else
+        $lazy_attributes = array_diff($lazy_attributes, $magic_params['with_lazy_attributes']);
+    }
+    
     $fields = $object->getDbTable()->getColumnsForSelect($table_name, $lazy_attributes, $prefix);
     foreach($fields as $field => $alias)
       $this->addField($field, $alias);

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-22 11:55:02 UTC (rev 7127)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php	2008-07-22 12:32:13 UTC (rev 7128)
@@ -29,7 +29,7 @@
     $this->_checkLazyness($object2, $annotation, $content);
   }
 
-  function testForceToLoadLazyAttributes()
+  function testForceToLoadAllLazyAttributes()
   {
     $object1 = $this->_createActiveRecord('Some annotation', 'Some content');
     $object2 = $this->_createActiveRecord('Some other annotation', 'Some other content');
@@ -42,6 +42,19 @@
     $this->assertTrue(array_key_exists('content', $arr[1]->exportRaw()));
   }
 
+  function testForceToLoadSomeLazyAttributes()
+  {
+    $object1 = $this->_createActiveRecord('Some annotation', 'Some content');
+    $object2 = $this->_createActiveRecord('Some other annotation', 'Some other content');
+    
+    $query = lmbARQuery :: create('LazyTestOneTableObject', $params = array('with_lazy_attributes' => array('annotation')));
+    $arr = $query->fetch()->getArray();
+    $this->assertTrue(array_key_exists('annotation', $arr[0]->exportRaw()));
+    $this->assertFalse(array_key_exists('content', $arr[0]->exportRaw()));
+    $this->assertTrue(array_key_exists('annotation', $arr[1]->exportRaw()));
+    $this->assertFalse(array_key_exists('content', $arr[1]->exportRaw()));
+  }
+  
   function testLazyWorksOkForEagerJoin_OneToOneRelations()
   {
     $person = new PersonForLazyAttributesTest();
@@ -59,6 +72,25 @@
     $lazy_object2 = $person_loaded->getLazyObject(); 
     $this->_checkLazyness($lazy_object2, $annotation, $content);
   }
+
+  function testForceToLoadAllLazyAttributes_ForEagerJoin_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' => array('lazy_object' => array('with_lazy_attributes' => ''))));
+    
+    $lazy_object2 = $person_loaded->getLazyObject(); 
+    $this->assertTrue(array_key_exists('annotation', $lazy_object2->exportRaw()));
+    $this->assertTrue(array_key_exists('content', $lazy_object2->exportRaw()));
+ }
   
   function testLazyWorksOkForEagerJoin_ForParentObject_OneToOneRelations()
   {



More information about the limb-svn mailing list