Permalink
Browse files

#11042 - Fix setting relation should not always cause dirty state change

  • Loading branch information...
Nochum Sossonko
Nochum Sossonko committed Oct 23, 2015
1 parent 23de7e9 commit cd1152a6ac1f827d0109003e38104a96896c26e2
Showing with 25 additions and 2 deletions.
  1. +6 −2 phalcon/mvc/model.zep
  2. +19 −0 unit-tests/ModelsRelationsTest.php
View
@@ -4089,17 +4089,21 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
public function __set(string property, value)
{
var lowerProperty, related, modelName, manager, lowerKey,
relation, referencedModel, key, item;
relation, referencedModel, key, item, dirtyState;
/**
* Values are probably relationships if they are objects
*/
if typeof value == "object" {
if value instanceof ModelInterface {
let dirtyState = this->_dirtyState;
if (value->getDirtyState() != dirtyState) {
let dirtyState = self::DIRTY_STATE_TRANSIENT;
}
let lowerProperty = strtolower(property),
this->{lowerProperty} = value,
this->_related[lowerProperty] = value,
this->_dirtyState = self::DIRTY_STATE_TRANSIENT;
this->_dirtyState = dirtyState;
return value;
}
}
@@ -75,6 +75,7 @@ public function testModelsMysql()
$this->_executeTestsNormal($di);
$this->_executeTestsRenamed($di);
$this->_testIssue938($di);
$this->_testIssue11042();
}
public function testModelsPostgresql()
@@ -94,6 +95,7 @@ public function testModelsPostgresql()
$this->_executeTestsNormal($di);
$this->_executeTestsRenamed($di);
$this->_testIssue11042();
}
@@ -115,6 +117,7 @@ public function testModelsSqlite()
$this->_executeTestsNormal($di);
$this->_executeTestsRenamed($di);
$this->_testIssue938($di);
$this->_testIssue11042();
}
public function _executeTestsNormal($di)
@@ -367,4 +370,20 @@ protected function _testIssue938($di)
$this->assertEquals($rp[$i]->robots_id, $robot->id);
}
}
protected function _testIssue11042()
{
$robot = RelationsRobots::findFirst();
$this->assertNotEquals($robot, false);
$this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT);
$robotsParts = $robot->getRelationsRobotsParts();
$this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT);
$robot = RelationsRobots::findFirst();
$this->assertNotEquals($robot, false);
$robotsParts = $robot->relationsRobotsParts;
$this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT);
}
}

0 comments on commit cd1152a

Please sign in to comment.