Commit a2f4eca3 authored by Jens Segers's avatar Jens Segers

Fix getDirty check for dates, fixes #373

parent 712c88a6
......@@ -355,6 +355,29 @@ abstract class Model extends BaseModel {
return $attributes;
}
/**
* Determine if the new and old values for a given key are numerically equivalent.
*
* @param string $key
* @return bool
*/
protected function originalIsNumericallyEquivalent($key)
{
$current = $this->attributes[$key];
$original = $this->original[$key];
// Date comparison.
if (in_array($key, $this->getDates()))
{
$current = $current instanceof MongoDate ? $this->asDateTime($current) : $current;
$original = $original instanceof MongoDate ? $this->asDateTime($original) : $original;
return $current == $original;
}
return parent::originalIsNumericallyEquivalent($key);
}
/**
* Remove one or more fields.
*
......
......@@ -490,4 +490,14 @@ class ModelTest extends TestCase {
$this->assertEquals('Paris', $user->{'address.city'});
}
public function testGetDirtyDates()
{
$user = new User();
$user->setRawAttributes(['name' => 'John Doe', 'birthday' => new DateTime('19 august 1989')], true);
$this->assertEmpty($user->getDirty());
$user->birthday = new DateTime('19 august 1989');
$this->assertEmpty($user->getDirty());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment