@@ -482,7 +482,7 @@ public static function query(Query $query): QueryResult
482482 }
483483
484484 if (static ::$ registry ) {
485- if ($ query instanceof SelectQuery && $ result ->wasSuccessful () && count ( $ result ) > 0 ) {
485+ if ($ query instanceof SelectQuery && $ result ->wasSuccessful () && $ query -> shouldSaveResultsToRegistry () ) {
486486 foreach ($ result as $ model ) {
487487 if ($ model ->getId () === null ) {
488488 continue ;
@@ -511,16 +511,18 @@ public static function query(Query $query): QueryResult
511511 * @param array|null $fields
512512 * @param array|int|Limit|null $limit
513513 * @param array|GroupField[]|string[]|null $group
514+ * @param bool $saveResultsToRegistry Whether results of this query should be saved in the model registry.
514515 * @return QueryResult<static>|static[]
515516 * @noinspection PhpDocSignatureInspection
516517 */
517518 public static function select (null |WhereCondition |array |WhereGroup $ where = null ,
518519 null |array $ order = null ,
519520 null |array $ fields = null ,
520521 null |Limit |array |int $ limit = null ,
521- null |array $ group = null ): QueryResult
522+ null |array $ group = null ,
523+ bool $ saveResultsToRegistry = true ): QueryResult
522524 {
523- return static ::query (new SelectQuery ($ where , $ order , $ fields , $ limit , $ group ));
525+ return static ::query (new SelectQuery ($ where , $ order , $ fields , $ limit , $ group, $ saveResultsToRegistry ));
524526 }
525527
526528 /**
@@ -697,4 +699,4 @@ public static function search(Search $search): SearchResult
697699
698700 return $ result ;
699701 }
700- }
702+ }
0 commit comments