浏览代码

folder_count

peterguo 1 月之前
父节点
当前提交
a80e5feabc
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      app/Http/Controllers/API/ContainerController.php
  2. 6 0
      app/Models/Container.php

+ 1 - 1
app/Http/Controllers/API/ContainerController.php

@@ -220,7 +220,7 @@ class ContainerController extends Controller
 
     public function linkage(string $libraryId)
     {
-        $items = Container::query()->allowed()->where("library_id", $libraryId)->get(['id', 'name'])->each(function ($items) {
+        $items = Container::withCount('folder')->allowed()->where("library_id", $libraryId)->get(['id', 'name'])->each(function ($items) {
             // 设置固定的type值
             $items->type = 'container';
             $items->uniId=$items->type.'_'.$items->id;

+ 6 - 0
app/Models/Container.php

@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use App\Models\Enums\ActionObjectType;
 use App\Models\Enums\ContainerACL;
 use App\Models\Scopes\CompanyScope;
 use EloquentFilter\Filterable;
@@ -62,4 +63,9 @@ class Container extends Model
 
         return $this->hasOne(ContainerContent::class, "container_id")->where("version", $version);
     }
+
+    public function folder()
+    {
+        return $this->hasMany(Folder::class, "object_id")->where("object_type", ActionObjectType::CONTAINER->value);
+    }
 }