Skip to content

Commit

Permalink
chore: send a model interface on get document from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandocavassani committed Oct 18, 2022
1 parent a220f85 commit 269466f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Model/HasLegacyRelationsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ protected function referencesOne(string $entity, string $field, bool $cacheable
$referencedId = $referencedId[0];
}

if ($cacheable && $document = $this->getDocumentFromCache($entity, $referencedId)) {
$entityInstance = Container::make($entity);

if ($cacheable && $referencedId && $document = $this->getDocumentFromCache($entityInstance, $referencedId)) {
return $document;
}

$entityInstance = Container::make($entity);
if ($entityInstance instanceof Schema) {
$dataMapper = Container::make(DataMapper::class);
$dataMapper->setSchema($entityInstance);
Expand Down Expand Up @@ -192,14 +193,8 @@ public function detach(string $field, &$obj)
* @return mixed|null
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
private function getDocumentFromCache(string $entity, ?string $referencedId)
private function getDocumentFromCache(ModelInterface $entityInstance, string $referencedId)
{
if (!$referencedId) {
return null;
}

$entityInstance = Container::make($entity);

/** @var CacheComponentInterface $cacheComponent */
$cacheComponent = Container::make(CacheComponentInterface::class);
$cacheKey = $this->generateCacheKey($entityInstance, $referencedId);
Expand Down

0 comments on commit 269466f

Please sign in to comment.