Bugfix #37

Merged
merged 2 commits into from Apr 17, 2012
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;
}
View
6 src/morph/property/Date.php
@@ -61,7 +61,7 @@ public function __getRawValue()
* @param $value
* @return Morph_Property_Generic
*/
- public function __setRawValue($value)
+ public function __setRawValue($value, $state = null)
{
if ($value instanceof \MongoDate) {
$this->value = (int) $value->sec;
@@ -72,6 +72,10 @@ public function __setRawValue($value)
$this->value = null;
}
}
+
+ if (null != $state) {
+ $this->state = $state;
+ }
return $this;
}