@@ -527,6 +527,16 @@ class Model {
527527 return new $ class ();
528528 }
529529
530+ /**
531+ * Clears the object cache for this Model class.
532+ */
533+ public static function clear_object_cache (): void {
534+ $ class = get_called_class ();
535+ if (isset (self ::$ object_cache [$ class ])) {
536+ unset(self ::$ object_cache [$ class ]);
537+ }
538+ }
539+
530540 /**
531541 * Provides this Model's Field object properties relevant information like its field name and provides this Model
532542 * object as this Field's $context Model object.
@@ -2108,6 +2118,9 @@ class Model {
21082118
21092119 # Refresh the initial object
21102120 $ this ->initial_object = $ this ->copy ();
2121+
2122+ # Clear the object cache for this Model class
2123+ $ this ->clear_object_cache ();
21112124 }
21122125
21132126 # Return the current representation of this object
@@ -2198,6 +2211,9 @@ class Model {
21982211
21992212 # Refresh the initial object
22002213 $ this ->initial_object = $ this ->copy ();
2214+
2215+ # Clear the object cache for this Model class
2216+ $ this ->clear_object_cache ();
22012217 }
22022218
22032219 # Return the current representation of this object
@@ -2293,6 +2309,9 @@ class Model {
22932309 clear_subsystem_dirty ($ this ->subsystem );
22942310 }
22952311
2312+ # Clear the object cache for this Model class
2313+ $ this ->clear_object_cache ();
2314+
22962315 return $ new_objects ;
22972316 }
22982317
@@ -2376,6 +2395,9 @@ class Model {
23762395
23772396 # Refresh the initial object
23782397 $ this ->initial_object = $ this ->copy ();
2398+
2399+ # Clear the object cache for this Model class
2400+ $ this ->clear_object_cache ();
23792401 }
23802402
23812403 # Return the current representation of this object
@@ -2425,8 +2447,10 @@ class Model {
24252447 offset: $ offset ,
24262448 );
24272449
2428- # Delete the Model objects that matched the query
2429- return $ model_objects ->delete ();
2450+ # Delete the Model objects that matched the query and clear the object cache
2451+ $ deleted_model_objects = $ model_objects ->delete ();
2452+ self ::clear_object_cache ();
2453+ return $ deleted_model_objects ;
24302454 }
24312455
24322456 /**
@@ -2436,8 +2460,10 @@ class Model {
24362460 # Obtain all Model objects for this Model
24372461 $ model_objects = self ::read_all ();
24382462
2439- # Delete all Model objects for this Model
2440- return $ model_objects ->delete ();
2463+ # Delete all Model objects for this Model and clear the object cache
2464+ $ deleted_model_objects = $ model_objects ->delete ();
2465+ self ::clear_object_cache ();
2466+ return $ deleted_model_objects ;
24412467 }
24422468
24432469 /**
0 commit comments