Skip to content

Commit

Permalink
introduced the "parent" relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
franzose committed Oct 5, 2020
1 parent 66a7af5 commit c4f53b9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model as Eloquent;
use Franzose\ClosureTable\Contracts\EntityInterface;
use Franzose\ClosureTable\Extensions\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;
use InvalidArgumentException;
Expand Down Expand Up @@ -354,6 +355,16 @@ public function getParent(array $columns = ['*'])
return $this->exists ? $this->find($this->parent_id, $columns) : null;
}

/**
* Returns many-to-one relationship to the direct ancestor.
*
* @return BelongsTo
*/
public function parent()
{
return $this->belongsTo(get_class($this), $this->getParentIdColumn());
}

/**
* Returns query builder for ancestors.
*
Expand Down

0 comments on commit c4f53b9

Please sign in to comment.