Skip to content

Commit

Permalink
Allow single model as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Jun 5, 2024
1 parent a0dbadf commit 6ae8e85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Models/Behaviors/HasRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public function loadRelated(string $browserName): Collection
*
* @param array<int, Model|array> $items
*/
public function saveRelated(array|Collection $items, string $browserName): void
public function saveRelated(array|Collection|Model $items, string $browserName): void
{
$items = collect($items);

/** @var Collection<int, RelatedItem> $itemsToProcess */
$itemsToProcess = $this->relatedItems()->where('browser_name', $browserName)->get();

Expand Down
7 changes: 1 addition & 6 deletions tests/integration/Controllers/Tables/BrowserColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ public function testWithSingleValue(): void
$category = $this->createCategory();

$this->author->saveRelated(
[
[
'id' => $category->id,
'endpointType' => Category::class,
],
],
$category,
'categories'
);

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/NplusOneRelatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSingleRelatedItem(): void
'published' => true,
]);

$storeArray[] = ['endpointType' => Writer::class, 'id' => $writer->id];
$storeArray[] = $writer;
}

$letter->saveRelated($storeArray, 'dummyBrowser');
Expand Down

0 comments on commit 6ae8e85

Please sign in to comment.