@@ -36,7 +36,7 @@ public function __construct(?Model $model = null)
36
36
{
37
37
parent ::__construct ($ model );
38
38
39
- // 初始化模型
39
+ // 初始化模型数据
40
40
$ this ->initData ();
41
41
}
42
42
@@ -45,7 +45,7 @@ public function __construct(?Model $model = null)
45
45
*
46
46
* @return void
47
47
*/
48
- public function initData ()
48
+ protected function initData ()
49
49
{
50
50
if ($ this ->isEmpty ()) {
51
51
return ;
@@ -108,7 +108,6 @@ private function fetchViewAttr(string $field)
108
108
}
109
109
}
110
110
}
111
-
112
111
return $ value ;
113
112
}
114
113
@@ -146,7 +145,6 @@ private function getEntityPropertiesMap(): array
146
145
$ properties [] = $ field ;
147
146
}
148
147
}
149
-
150
148
$ this ->setOption ('view_properties ' , $ properties );
151
149
}
152
150
@@ -192,9 +190,7 @@ public function data(array $data)
192
190
*/
193
191
public function refresh ()
194
192
{
195
- if ($ this ->isEmpty ()) {
196
- $ this ->initData ();
197
- }
193
+ $ this ->initData ();
198
194
return $ this ;
199
195
}
200
196
@@ -450,9 +446,8 @@ public static function create(array | object $data)
450
446
{
451
447
$ entity = new static ();
452
448
$ model = $ entity ->model ()->exists (false )->save ($ data , true );
453
- $ entity ->refresh ();
454
-
455
- return $ entity ;
449
+ // 刷新视图模型数据
450
+ return $ entity ->refresh ();
456
451
}
457
452
458
453
/**
@@ -468,9 +463,7 @@ public static function update(array | object $data, $where = [], array $allowFie
468
463
$ entity = new static ();
469
464
$ model = $ entity ->model ()->allowField ($ allowField )->exists (true )->save ($ data , $ where , true );
470
465
// 刷新视图模型数据
471
- $ entity ->refresh ();
472
-
473
- return $ entity ;
466
+ return $ entity ->refresh ();
474
467
}
475
468
476
469
/**
@@ -571,7 +564,7 @@ public static function __callStatic($method, $args)
571
564
// 调用model的静态方法
572
565
$ db = $ entity ->model ();
573
566
} else {
574
- // 调用Query类查询方法
567
+ // 处理字段映射
575
568
$ map = $ entity ->getOption ('viewMapping ' , []);
576
569
$ db = $ entity ->model ()->db ()->fieldMap ($ map );
577
570
}
0 commit comments