Skip to content
Merged
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
20 changes: 9 additions & 11 deletions src/Database/Barry/Relations/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,34 @@
use Bow\Cache\Cache;
use Bow\Database\Barry\Model;
use Bow\Database\Barry\Relation;
use Bow\Database\Exception\QueryBuilderException;

class HasOne extends Relation
{
/**
* Create a new belongs to relationship instance.
*
* @param Model $related
* @param Model $parent
* @param string $foreign_key
* @param string $local_key
* @param Model $related
* @param Model $parent
* @param string $foreign_key
* @param string $local_key
*/
public function __construct(Model $related, Model $parent, string $foreign_key, string $local_key)
{
parent::__construct($related, $parent);

$this->local_key = $local_key;
$this->foreign_key = $foreign_key;

parent::__construct($related, $parent);
}

/**
* Get the results of the relationship.
*
* @return Model|null
* @return Model
*/
public function getResults(): mixed
public function getResults(): ?Model
{
$key = $this->query->getTable() . ":hasone:" . $this->related->getTable() . ":" . $this->foreign_key;

$cache = Cache::store('file')->get($key);

if (!is_null($cache)) {
Expand All @@ -57,7 +56,6 @@ public function getResults(): mixed
* Set the base constraints on the relation query.
*
* @return void
* @throws QueryBuilderException
*/
public function addConstraints(): void
{
Expand Down
Loading