File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,14 @@ public function toArray(): array
148148 // 输出额外属性 必须定义获取器
149149 foreach ($ this ->getOption ('append ' ) as $ key => $ field ) {
150150 if (is_numeric ($ key )) {
151- $ item [$ field ] = $ this ->get ($ field );
151+ if (strpos ($ field , '. ' )) {
152+ [$ name , $ field ] = explode ('. ' , $ field , 2 );
153+ $ relation = $ this ->getRelationData ($ name , false );
154+ $ value = $ relation ?->get($ field );
155+ } else {
156+ $ value = $ this ->get ($ field );
157+ }
158+ $ item [$ field ] = $ value ;
152159 } else {
153160 // 追加关联属性
154161 $ relation = $ this ->getRelationData ($ key , false );
Original file line number Diff line number Diff line change 1616use Closure ;
1717use think \db \BaseQuery as Query ;
1818use think \Model ;
19+ use think \model \Collection ;
1920
2021/**
2122 * 数据软删除
@@ -96,15 +97,23 @@ public function delete(): bool
9697 $ force = $ this ->isForce ();
9798
9899 if ($ name && !$ force ) {
100+ foreach ($ this ->getData () as $ name => $ val ) {
101+ if ($ val instanceof Model || $ val instanceof Collection) {
102+ $ relations [$ name ] = $ val ;
103+ }
104+ }
99105 // 软删除
100106 $ this ->exists ()->withEvent (false )->save ([$ name => $ this ->getDateTime ($ name )]);
101107
102108 $ this ->withEvent (true );
103-
109+ if (!empty ($ relations )) {
110+ // 删除关联数据
111+ $ this ->relationDelete ($ relations );
112+ }
104113 $ this ->trigger ('AfterDelete ' );
105114 $ this ->exists (false );
106115 $ this ->clear ();
107- return true ;
116+ return true ;
108117 }
109118 return parent ::delete ();
110119 }
You can’t perform that action at this time.
0 commit comments