Skip to content

Commit 221883b

Browse files
author
Ethan
committed
with
1 parent 83803a1 commit 221883b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ModelTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public function hasMany($related, $foreignKey = null, $localKey = 'id')
145145
/**
146146
* 渴求式加载
147147
*
148+
* eg. Blog::with('category')->where()->findAll()
149+
*
148150
* @param string|array $relations 关联名称
149151
*/
150152
public static function with($relations)
@@ -154,8 +156,8 @@ public static function with($relations)
154156
return DB::table(static::tableName())->asEntity(static::className())->afterFind(function ($models) use ($relations) {
155157
if (count($models) > 0) {
156158
foreach ($relations as $relation) {
157-
$relation = call_user_func([$models[0], $relation]);
158-
$relation->appendData($models, $relation);
159+
$relationObj = call_user_func([$models[0], $relation]);
160+
$relationObj->appendData($models, $relation);
159161
}
160162
}
161163
});

0 commit comments

Comments
 (0)