@@ -64,14 +64,19 @@ protected function primaryKey(): string
6464 */
6565 public function get ($ columns = null ): array
6666 {
67- $ this ->applyWiths ();
67+ $ this ->applyRelationsBefore ();
68+
6869 if ($ columns ) $ this ->select (...func_get_args ());
6970 $ models = $ this ->query ()->objectAll ($ this ->model );
71+ if (!$ models ) return $ models ;
72+ $ ids = [];
7073 foreach ($ models as &$ model ) {
7174 $ model = $ model ->identityMapSave ();
72- if (0 < count ($ this ->withs )) $ this ->parseWiths ($ model );
75+ if (0 < count ($ this ->withOne )) $ this ->parseWiths ($ model );
76+ $ ids [] = $ model ->primaryValue ();
7377 }
74- $ models = array_unique ($ models );
78+ // $models = array_unique($models);
79+ $ this ->applyRelationsAfter ($ ids , $ models );
7580 return $ models ;
7681 }
7782
@@ -80,14 +85,15 @@ public function get($columns = null): array
8085 * @param array|null столбцы для получения
8186 * @return array|null найденная запись
8287 */
83- public function one ($ columns = null )
88+ public function one ($ columns = null )
8489 {
85- $ this ->applyWiths ();
90+ $ this ->applyRelationsBefore ();
8691 if ($ columns ) $ this ->select (...func_get_args ());
8792 $ model = $ this ->limit (1 )->query ()->object ($ this ->model );
8893 if ($ model ) {
89- if (0 < count ($ this ->withs )) $ this ->parseWiths ($ model );
94+ if (0 < count ($ this ->withOne )) $ this ->parseWiths ($ model );
9095 $ model = $ model ->identityMapSave ();
96+ $ this ->applyRelationsAfter ([$ model ->primaryValue (), [$ model ]]);
9197 }
9298 return $ model ;
9399 // return is_null($model) ? $model : $model->identityMapSave();
0 commit comments