ソースを参照

Merge pull request #10366 from cleptric/issue-10292

Add getDirty method
Mark Story 9 年 前
コミット
adbe886fea
2 ファイル変更32 行追加0 行削除
  1. 10 0
      src/Datasource/EntityTrait.php
  2. 22 0
      tests/TestCase/ORM/EntityTest.php

+ 10 - 0
src/Datasource/EntityTrait.php

@@ -777,6 +777,16 @@ trait EntityTrait
     }
 
     /**
+     * Gets the dirty properties.
+     *
+     * @return array
+     */
+    public function getDirty()
+    {
+        return array_keys($this->_dirty);
+    }
+
+    /**
      * Sets the entire entity as clean, which means that it will appear as
      * no properties being modified or added at all. This is an useful call
      * for an initial object hydration

+ 22 - 0
tests/TestCase/ORM/EntityTest.php

@@ -840,6 +840,28 @@ class EntityTest extends TestCase
     }
 
     /**
+     * Tests the getDirty method
+     *
+     * @return void
+     */
+    public function testGetDirty()
+    {
+        $entity = new Entity([
+            'id' => 1,
+            'title' => 'Foo',
+            'author_id' => 3
+        ]);
+
+        $expected = [
+            'id',
+            'title',
+            'author_id'
+        ];
+        $result = $entity->getDirty();
+        $this->assertSame($expected, $entity->getDirty());
+    }
+
+    /**
      * Tests the clean method
      *
      * @return void