From 42f6178b6d3bbf8b5622f6878dc6d34c9f331e0d Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Mon, 19 Jan 2026 21:33:38 +0100 Subject: [PATCH] Fix task collection attach relation --- .../RelationManagers/TasksRelationManager.php | 2 ++ app/Models/Task.php | 10 ++++++++++ tests/Unit/TaskCollectionsRelationTest.php | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/Unit/TaskCollectionsRelationTest.php diff --git a/app/Filament/Clusters/WeeklyOps/Resources/TaskCollections/RelationManagers/TasksRelationManager.php b/app/Filament/Clusters/WeeklyOps/Resources/TaskCollections/RelationManagers/TasksRelationManager.php index 8ecd6a2..42722f5 100644 --- a/app/Filament/Clusters/WeeklyOps/Resources/TaskCollections/RelationManagers/TasksRelationManager.php +++ b/app/Filament/Clusters/WeeklyOps/Resources/TaskCollections/RelationManagers/TasksRelationManager.php @@ -19,6 +19,8 @@ class TasksRelationManager extends RelationManager { protected static string $relationship = 'tasks'; + protected static ?string $inverseRelationship = 'taskCollections'; + public function table(Table $table): Table { return $table diff --git a/app/Models/Task.php b/app/Models/Task.php index dbd0194..64877f7 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -44,6 +44,16 @@ class Task extends Model return $this->belongsTo(TaskCollection::class, 'collection_id'); } + public function taskCollections(): BelongsToMany + { + return $this->belongsToMany( + TaskCollection::class, + 'task_collection_task', + 'task_id', + 'task_collection_id' + )->withPivot(['sort_order']); + } + public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); diff --git a/tests/Unit/TaskCollectionsRelationTest.php b/tests/Unit/TaskCollectionsRelationTest.php new file mode 100644 index 0000000..92f4d2c --- /dev/null +++ b/tests/Unit/TaskCollectionsRelationTest.php @@ -0,0 +1,19 @@ +taskCollections(); + + $this->assertInstanceOf(BelongsToMany::class, $relation); + $this->assertSame(['sort_order'], $relation->getPivotColumns()); + } +}