Browse files

Bugfix: a property set should be dirty if there are clean and new pro…

…perties
  • Loading branch information...
1 parent 66e3214 commit 4340a0c6a60895010143100476b83e4a55730c3f @daniphp daniphp committed Apr 6, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/morph/PropertySet.php
View
14 src/morph/PropertySet.php
@@ -81,15 +81,27 @@ public function __setRawPropertyValue($name, $value, $state = null)
public function getState()
{
$state = \morph\Enum::STATE_NEW;
+ $hasCleanProperty = false;
+ $hasNewProperty = false;
+
foreach ($this as $n => $property) {
$propertyState = $property->getState();
if ( \morph\Enum::STATE_DIRTY == $propertyState) {
$state = $propertyState;
break;
} elseif ( \morph\Enum::STATE_CLEAN == $propertyState) {
$state = $propertyState;
+ $hasCleanProperty = true;
+ } elseif ( \morph\Enum::STATE_NEW == $propertyState) {
+ $state = $propertyState;
+ $hasNewProperty = true;
}
- }
+ }
+
+ if ($hasCleanProperty && $hasNewProperty) {
+ return \morph\Enum::STATE_DIRTY;
+ }
+
return $state;
}

0 comments on commit 4340a0c

Please sign in to comment.