File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -39,22 +39,31 @@ public function __construct(?Model $model = null, bool $with = false)
39
39
$ this ->model ()->asView (true );
40
40
41
41
// 初始化模型
42
- if (!$ this ->isEmpty () && ! $ with ) {
43
- $ this ->initData ();
42
+ if (!$ this ->isEmpty ()) {
43
+ $ this ->initData ($ with );
44
44
}
45
45
}
46
46
47
47
/**
48
48
* 初始化实体数据属性(如果存在关联查询则会延迟执行).
49
49
*
50
+ * @param bool $with 是否处理关联数据
50
51
* @return void
51
52
*/
52
- public function initData ()
53
+ public function initData (bool $ with = true )
53
54
{
54
55
// 获取实体属性
55
56
$ properties = $ this ->getEntityProperties ();
56
57
$ data = $ this ->model ()->getData ();
57
58
foreach ($ properties as $ key => $ field ) {
59
+ if (!$ with ) {
60
+ // 确保存在基础模型数据
61
+ if (isset ($ data [$ field ])) {
62
+ $ this ->$ field = $ data [$ field ];
63
+ }
64
+ continue ;
65
+ }
66
+
58
67
if (is_int ($ key )) {
59
68
$ this ->$ field = $ this ->fetchViewAttr ($ field );
60
69
} elseif (strpos ($ field , '-> ' )) {
You can’t perform that action at this time.
0 commit comments