Permalink
Browse files

Merge pull request #36 from daniphp/4340a0c6a60895010143100476b83e4a5…

…5730c3f

a property set should be dirty if there are clean and new propertiesBugfix: a property set should be dirty if there are clean and new properties - Thanks daniphp
  • Loading branch information...
2 parents 9a8f968 + 4340a0c commit cce7a14592dfd7301ac510943056892803ae3451 Jonathan Moss committed Apr 17, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/morph/PropertySet.php
View
@@ -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 cce7a14

Please sign in to comment.