[limb-svn] r5829 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Tue May 8 13:01:53 MSD 2007
Author: serega
Date: 2007-05-08 13:01:52 +0400 (Tue, 08 May 2007)
New Revision: 5829
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5829
Modified:
3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php
Log:
-- $_has_one and $_many_belongs_to relations in lmbActiveRecord do not set object as dirty if relation field did not change in _savePreRelationObject();
Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-05-07 20:52:07 UTC (rev 5828)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-05-08 09:01:52 UTC (rev 5829)
@@ -337,7 +337,9 @@
if(is_object($object))
{
$object->save($this->getErrorList());
- $this->_setRaw($info['field'], $object->getId());
+ $object_id = $object->getId();
+ if($this->_getRaw($info['field']) != $object_id)
+ $this->_setRaw($info['field'], $object->getId());
}
elseif(is_null($object) && $this->isDirtyProperty($property) &&
isset($info['can_be_null']) && $info['can_be_null'])
@@ -1249,6 +1251,11 @@
return $items;
}
+ static function getInheritanceClass($obj)
+ {
+ return end(self :: decodeInheritancePath($obj[self :: $_inheritance_field]));
+ }
+
/**
* Loads current object with data from database, overwrites any previous data, marks object dirty and unsets new status
* @param integer object id
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php 2007-05-07 20:52:07 UTC (rev 5828)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToOneRelationsTest.class.php 2007-05-08 09:01:52 UTC (rev 5829)
@@ -1,22 +1,29 @@
<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright Copyright © 2004-2007 BIT
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- * @version $Id$
- * @package active_record
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright Copyright © 2004-2007 BIT
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version $Id$
+ * @package active_record
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
class PersonForTest extends lmbActiveRecord
{
+ public $save_count = 0;
protected $_has_one = array('social_security' => array('field' => 'ss_id',
'class' => 'SocialSecurityForTest',
'can_be_null' => true));
+
+ function _onSave()
+ {
+ $this->save_count++;
+ }
+
}
class PersonForTestNoCascadeDelete extends lmbActiveRecord
@@ -100,6 +107,27 @@
$this->assertNotNull($person->getId());
}
+ function testDontSaveParentSecondTimeIfChildWasChanged()
+ {
+ $person = new PersonForTest();
+ $person->setName('Jim');
+
+ $number = new SocialSecurityForTest();
+ $number->setCode('099123');
+
+ $person->setSocialSecurity($number);
+ $person->save();
+
+ $this->assertEqual($person->save_count, 1);
+
+ $number->setCode($new_code = '0022112');
+ $person->save();
+
+ $this->assertEqual($person->save_count, 1);
+ $loaded_number = new SocialSecurityForTest($number->getId());
+ $this->assertEqual($loaded_number->getCode(), $new_code);
+ }
+
function testLoadParentObject()
{
$person = new PersonForTest();
More information about the limb-svn
mailing list