[limb-svn] r6980 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Sun May 4 12:26:58 MSD 2008
Author: serega
Date: 2008-05-04 12:26:58 +0400 (Sun, 04 May 2008)
New Revision: 6980
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6980
Modified:
3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php
3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php
Log:
-- fixed a bug in lmbARRecordSetAttachDecorator that didn't initialized related collections properly in case if related objects were not loaded for base collection (due to some criteria for example). See lmbARQueryTest :: testFetch_Attach_RelatedHasMany_WithCriteriaForAttach()
Modified: 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php 2008-05-03 12:36:52 UTC (rev 6979)
+++ 3.x/trunk/limb/active_record/src/lmbARRecordSetAttachDecorator.class.php 2008-05-04 08:26:58 UTC (rev 6980)
@@ -154,6 +154,8 @@
$collection->setOwner($object);
if(isset($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())]))
$collection->setDataset(new lmbCollection($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())]));
+ else
+ $collection->setDataset(new lmbCollection());
$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-05-03 12:36:52 UTC (rev 6979)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php 2008-05-04 08:26:58 UTC (rev 6980)
@@ -336,6 +336,43 @@
$this->assertEqual($this->conn->countQueries(), 0);
}
+ function testFetch_Attach_RelatedHasMany_WithCriteriaForAttach()
+ {
+ $course1 = $this->creator->createCourse();
+ $course2 = $this->creator->createCourse();
+
+ $lecture1 = $this->creator->createLecture($course1, null, 'ZZZ');
+ $lecture2 = $this->creator->createLecture($course2, null, 'CCC');
+ $lecture3 = $this->creator->createLecture($course1, null, 'AAA');
+
+ $query = lmbARQuery :: create('CourseForTest', array(), $this->conn);
+ $arr = $query->eagerAttach('lectures', array('criteria' => lmbSQLCriteria :: equal('title', 'CCC')))->fetch()->getArray();
+
+ $this->conn->resetStats();
+
+ $this->assertIsA($arr[0], 'CourseForTest');
+ $this->assertEqual($arr[0]->getTitle(), $course1->getTitle());
+ $lectures = $arr[0]->getLectures();
+ $this->assertEqual(count($lectures), 0);
+
+ $this->assertIsA($arr[1], 'CourseForTest');
+ $this->assertEqual($arr[1]->getTitle(), $course2->getTitle());
+ $lectures = $arr[1]->getLectures();
+ $this->assertEqual(count($lectures), 1);
+ $this->assertEqual($lectures[0]->getId(), $lecture2->getId());
+ $this->assertEqual($lectures[0]->getTitle(), 'CCC');
+
+ $this->assertEqual($this->conn->countQueries(), 0);
+
+ // let's change the first course and save it. The lectures should stay in database
+ $arr[0]->setTitle('Changed');
+ $arr[0]->save();
+
+ $loaded_course = new CourseForTest($course1->getId());
+ $lectures = $loaded_course->getLectures();
+ $this->assertEqual(count($lectures), 2);
+ }
+
function testFetch_Attach_WithEmptyRS_ForRelatedHasMany()
{
$this->conn->resetStats();
@@ -701,7 +738,7 @@
$this->assertEqual($arr[0]->getCourses()->count(), 0);
$this->assertEqual($arr[1]->getCourses()->count(), 0);
- $this->assertEqual($this->conn->countQueries(), 2); // always do fetchi operations for not new owners of collections
+ $this->assertEqual($this->conn->countQueries(), 0);
}
function testFetch_JoinWithWrongRelationType()
More information about the limb-svn
mailing list