Skip to content

Commit

Permalink
Improved relation support
Browse files Browse the repository at this point in the history
  • Loading branch information
libern committed Aug 16, 2018
1 parent dc303ac commit d5450bf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Libern\LaravelClickHouse\Database\Eloquent\Concerns;

use LogicException;
use Illuminate\Database\Eloquent\Relations\Relation as BaseRelation;
use Libern\LaravelClickHouse\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Concerns\HasAttributes as BaseHasAttributes;

trait HasAttributes
Expand All @@ -24,4 +27,19 @@ protected function getDateFormat(): string
{
return $this->dateFormat ?? 'Y-m-d H:i:s';
}

protected function getRelationshipFromMethod($method)
{
$relation = $this->$method();

if (! ($relation instanceof Relation || $relation instanceof BaseRelation)) {
throw new LogicException(sprintf(
'%s::%s must return a relationship instance.', static::class, $method
));
}

return tap($relation->getResults(), function ($results) use ($method) {
$this->setRelation($method, $results);
});
}
}

0 comments on commit d5450bf

Please sign in to comment.