File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1515 * You can obtain one at https://mozilla.org/MPL/2.0/.
1616 * @license MPL-2.0 https://mozilla.org/MPL/2.0/
1717 * @source https://github.com/wdes/simple-php-model-system
18+ * @version 1.1.0
1819 */
1920
2021abstract class AbstractModel
@@ -70,6 +71,14 @@ public function getValue(string $key)
7071 return $ this ->data [$ key ] ?? null ;
7172 }
7273
74+ /**
75+ * @since 1.1.0
76+ */
77+ public function hasChanges (): bool
78+ {
79+ return count ($ this ->keysToModify ) > 0 ;
80+ }
81+
7382 public function save (): bool
7483 {
7584 $ keys = implode (', ' , $ this ->getKeys ());
@@ -412,6 +421,10 @@ public function setData(array $data): void
412421 */
413422 protected function set ($ key , $ value ): void
414423 {
424+ if ($ this ->data [$ key ] === $ value ) {
425+ return ;// No changes to apply
426+ }
427+
415428 $ this ->data [$ key ] = $ value ;
416429 $ this ->keysToModify [$ key ] = true ;
417430 }
You can’t perform that action at this time.
0 commit comments