Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Models/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ protected static function buildNestedTree(Collection $taxonomies): Collection
} else {
// Child level - add to parent's children collection
$parent = end($stack);
if ($parent && ! $parent->children_nested) {
if ($parent && empty($parent->children_nested)) {
/** @var \Illuminate\Database\Eloquent\Collection<int, static> $childrenNested */
$childrenNested = new Collection;
$parent->setAttribute('children_nested', $childrenNested);
Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/NestedSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Aliziodev\LaravelTaxonomy\Enums\TaxonomyType;
use Aliziodev\LaravelTaxonomy\Models\Taxonomy;
use Aliziodev\LaravelTaxonomy\Tests\TestCase;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(TestCase::class, RefreshDatabase::class);
Expand Down Expand Up @@ -328,3 +329,9 @@ function createTestTaxonomies(): void
expect($techTag->isAncestorOf($electronics))->toBeFalse();
expect($electronics->isAncestorOf($techTag))->toBeFalse();
});

it('works when models are strict', function () {
Model::shouldBeStrict();
$tree = Taxonomy::getNestedTree(TaxonomyType::Category);
expect($tree)->toHaveCount(2);
});
Loading