Skip to content

Commit

Permalink
revised the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPunyapal committed Apr 3, 2023
1 parent ebbddd8 commit 334a9e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/Relations/BelongsToManyKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,12 @@ public function initRelation(array $models, $relation)
public function match(array $models, Collection $results, $relation)
{
$dictionary = $this->buildDictionary($results);

foreach ($models as $model) {
foreach ($this->localKeys as $localKey) {
$key = $model->getAttribute($localKey);
if (
isset($dictionary[$key])
) {
if (isset($dictionary[$key]))
$model->setRelation($this->relations[$localKey], $dictionary[$key]);
}
}
$model->unsetRelation($relation);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Relations/HasManyKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ public function addConstraints(): void
}
}

/**
* Get the key value of the parent's local key.
* Info: From HasOneOrMany class.
*
* @return mixed
*/
public function getParentKey()
{
return $this->parent->getAttribute($this->localKey);
}

/**
* Set the constraints for an eager load of the relation.
* Note: Used to load relations of multiple models at once.
Expand Down Expand Up @@ -158,6 +147,17 @@ protected function buildDictionary(Collection $models): array
return $dictionary;
}

/**
* Get the key value of the parent's local key.
* Info: From HasOneOrMany class.
*
* @return mixed
*/
public function getParentKey()
{
return $this->parent->getAttribute($this->localKey);
}

/**
* Get the results of the relationship.
*
Expand Down

0 comments on commit 334a9e3

Please sign in to comment.