Skip to content

Commit

Permalink
feat(term) added taxonomy relationship to term
Browse files Browse the repository at this point in the history
  • Loading branch information
oniice committed Sep 25, 2023
1 parent 2f95493 commit 1298fb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Myerscode\Laravel\Taxonomies;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Term extends Model
{

Expand All @@ -27,4 +29,12 @@ public static function addToTaxonomy($term, $taxonomy): self

return new static;
}

/**
* Taxonomy associated with the term
*/
public function taxonomy(): BelongsTo
{
return $this->belongsTo(Taxonomy::class);
}
}
12 changes: 11 additions & 1 deletion tests/TermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests;

use Myerscode\Laravel\Taxonomies\Exceptions\UnsupportedModelDataException;
use Myerscode\Laravel\Taxonomies\Taxonomy;
use Myerscode\Laravel\Taxonomies\Term;

class TermTest extends TestCase
Expand Down Expand Up @@ -62,4 +63,13 @@ public function testAddTermToTaxonomy()
$this->assertCount(2, Term::all());
}

}
public function testTermBelongsToTaxonomy()
{
Term::addToTaxonomy('Hello', 'World');
$term = Term::findByName('Hello');

$this->assertInstanceOf(Taxonomy::class, $term->taxonomy);
$this->assertEquals('World', $term->taxonomy->name);
}

}

0 comments on commit 1298fb2

Please sign in to comment.