[limb-svn] r5944 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Wed Jun 6 10:58:26 MSD 2007
Author: serega
Date: 2007-06-06 10:58:26 +0400 (Wed, 06 Jun 2007)
New Revision: 5944
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5944
Modified:
3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php
Log:
-- now it's allowed to change has_one and many_belongs_to relation fields properties directly. But if related object is a dirty property in active record then directly set relation field property will ignored.
See lmbActiveRecordOneToManyRelationsTest :: testChangingParentIdRelationFieldDirectly()
lmbActiveRecordOneToManyRelationsTest :: testChangingParentIdRelationFieldDirectlyDoesNotWorkIfParentObjectIsDirty()
and also
lmbActiveRecordOneToOneRelationsTest :: testChangingChildObjectIdDirectly()
lmbActiveRecordOneToOneRelationsTest :: testChangingChildIdRelationFieldDirectlyHasNoAffectIfChildObjectPropertyIsDirty()
-- lmbActiveRecord :: resetDirty() public method added.
Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-06-06 06:53:29 UTC (rev 5943)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-06-06 06:58:26 UTC (rev 5944)
@@ -1,10 +1,10 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/core/src/lmbObject.class.php');
lmb_require('limb/core/src/lmbDelegate.class.php');
@@ -372,7 +372,7 @@
protected function _savePreRelationObject($property, $info, $save_relation_obj = true)
{
- if($this->isDirtyProperty($info['field']))
+ if($this->isDirtyProperty($info['field']) && !$this->isDirtyProperty($property))
{
$value = $this->_getRaw($info['field']);
if(is_null($value))
@@ -604,6 +604,11 @@
return true;
}
+ function resetDirty()
+ {
+ $this->_resetDirty();
+ }
+
protected function _resetDirty()
{
$this->_is_dirty = false;
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php 2007-06-06 06:53:29 UTC (rev 5943)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php 2007-06-06 06:58:26 UTC (rev 5944)
@@ -1,10 +1,10 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/active_record/src/lmbAROneToManyCollection.class.php');
@@ -278,6 +278,53 @@
$this->assertEqual($course->save_calls, 1);
}
+ function testChangingParentIdRelationFieldDirectly()
+ {
+ $course1 = $this->_initCourse();
+ $course1->save();
+
+ $course2 = $this->_initCourse();
+ $course2->save();
+
+ $lecture = new LectureForTest();
+ $lecture->setTitle('Physics');
+ $lecture->setCourse($course1);
+ $lecture->save();
+
+ $lecture2 = new LectureForTest($lecture->getId());
+ $this->assertEqual($lecture2->getCourse()->getId(), $course1->getId());
+
+ $lecture2->set('course_id', $course2->getId());
+ $lecture2->save();
+
+ $lecture3 = new LectureForTest($lecture->getId());
+ $this->assertEqual($lecture3->getCourse()->getId(), $course2->getId());
+ }
+
+ function testChangingParentIdRelationFieldDirectlyDoesNotWorkIfParentObjectIsDirty()
+ {
+ $course1 = $this->_initCourse();
+ $course1->save();
+
+ $course2 = $this->_initCourse();
+ $course2->save();
+
+ $lecture = new LectureForTest();
+ $lecture->setTitle('Physics');
+ $lecture->setCourse($course1);
+ $lecture->save();
+
+ $lecture2 = new LectureForTest($lecture->getId());
+ $this->assertEqual($lecture2->getCourse()->getId(), $course1->getId());
+
+ $lecture2->set('course_id', $course2->getId());
+ $lecture2->setCourse($course1);
+ $lecture2->save();
+
+ $lecture3 = new LectureForTest($lecture->getId());
+ $this->assertEqual($lecture3->getCourse()->getId(), $course1->getId());
+ }
+
function testOwnerSetAutomaticallyForChildAddedToCollection()
{
$course = $this->_initCourse();
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php 2007-06-06 06:53:29 UTC (rev 5943)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php 2007-06-06 06:58:26 UTC (rev 5944)
@@ -1,10 +1,10 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
@@ -155,6 +155,57 @@
$this->assertEqual($loaded_number->getCode(), $new_code);
}
+ function testChangingChildObjectIdDirectly()
+ {
+ $person = new PersonForTest();
+ $person->setName('Jim');
+
+ $number1 = new SocialSecurityForTest();
+ $number1->setCode('099123');
+
+ $person->setSocialSecurity($number1);
+ $person->save();
+
+ $number2 = new SocialSecurityForTest();
+ $number2->setCode('143453');
+ $number2->save();
+
+ $person2 = new PersonForTest($person->getId());
+ $this->assertEqual($person2->getSocialSecurity()->getId(), $number1->getId());
+
+ $person2->set('ss_id', $number2->getId());
+ $person2->save();
+
+ $person3 = new PersonForTest($person->getId());
+ $this->assertEqual($person3->getSocialSecurity()->getId(), $number2->getId());
+ }
+
+ function testChangingChildIdRelationFieldDirectlyHasNoAffectIfChildObjectPropertyIsDirty()
+ {
+ $person = new PersonForTest();
+ $person->setName('Jim');
+
+ $number1 = new SocialSecurityForTest();
+ $number1->setCode('099123');
+
+ $person->setSocialSecurity($number1);
+ $person->save();
+
+ $number2 = new SocialSecurityForTest();
+ $number2->setCode('143453');
+ $number2->save();
+
+ $person2 = new PersonForTest($person->getId());
+ $this->assertEqual($person2->getSocialSecurity()->getId(), $number1->getId());
+
+ $person2->set('ss_id', $number2->getId()); // changing child relation field directly
+ $person2->setSocialSecurity($number1); // and making child object dirty
+ $person2->save();
+
+ $person3 = new PersonForTest($person->getId());
+ $this->assertEqual($person3->getSocialSecurity()->getId(), $number1->getId());
+ }
+
function testLoadParentObject()
{
$person = new PersonForTest();
@@ -305,6 +356,7 @@
$person->setSocialSecurity($number);
$number->setPerson($person);
+ $person->setNumber($number);
$person->save();
$number->destroy();
More information about the limb-svn
mailing list