Fix task collection attach relation
This commit is contained in:
@@ -19,6 +19,8 @@ class TasksRelationManager extends RelationManager
|
|||||||
{
|
{
|
||||||
protected static string $relationship = 'tasks';
|
protected static string $relationship = 'tasks';
|
||||||
|
|
||||||
|
protected static ?string $inverseRelationship = 'taskCollections';
|
||||||
|
|
||||||
public function table(Table $table): Table
|
public function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ class Task extends Model
|
|||||||
return $this->belongsTo(TaskCollection::class, 'collection_id');
|
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
|
public function tenant(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Tenant::class);
|
return $this->belongsTo(Tenant::class);
|
||||||
|
|||||||
19
tests/Unit/TaskCollectionsRelationTest.php
Normal file
19
tests/Unit/TaskCollectionsRelationTest.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Models\Task;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TaskCollectionsRelationTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_task_has_task_collections_relation(): void
|
||||||
|
{
|
||||||
|
$task = new Task;
|
||||||
|
$relation = $task->taskCollections();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(BelongsToMany::class, $relation);
|
||||||
|
$this->assertSame(['sort_order'], $relation->getPivotColumns());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user