@@ -482,7 +482,7 @@ public static function query(Query $query): QueryResult
482
482
}
483
483
484
484
if (static ::$ registry ) {
485
- if ($ query instanceof SelectQuery && $ result ->wasSuccessful () && count ( $ result ) > 0 ) {
485
+ if ($ query instanceof SelectQuery && $ result ->wasSuccessful () && $ query -> shouldSaveResultsToRegistry () ) {
486
486
foreach ($ result as $ model ) {
487
487
if ($ model ->getId () === null ) {
488
488
continue ;
@@ -511,16 +511,18 @@ public static function query(Query $query): QueryResult
511
511
* @param array|null $fields
512
512
* @param array|int|Limit|null $limit
513
513
* @param array|GroupField[]|string[]|null $group
514
+ * @param bool $saveResultsToRegistry Whether results of this query should be saved in the model registry.
514
515
* @return QueryResult<static>|static[]
515
516
* @noinspection PhpDocSignatureInspection
516
517
*/
517
518
public static function select (null |WhereCondition |array |WhereGroup $ where = null ,
518
519
null |array $ order = null ,
519
520
null |array $ fields = null ,
520
521
null |Limit |array |int $ limit = null ,
521
- null |array $ group = null ): QueryResult
522
+ null |array $ group = null ,
523
+ bool $ saveResultsToRegistry = true ): QueryResult
522
524
{
523
- return static ::query (new SelectQuery ($ where , $ order , $ fields , $ limit , $ group ));
525
+ return static ::query (new SelectQuery ($ where , $ order , $ fields , $ limit , $ group, $ saveResultsToRegistry ));
524
526
}
525
527
526
528
/**
@@ -697,4 +699,4 @@ public static function search(Search $search): SearchResult
697
699
698
700
return $ result ;
699
701
}
700
- }
702
+ }
0 commit comments