Skip to content

Commit 334a9e3

Browse files
committed
revised the code.
1 parent ebbddd8 commit 334a9e3

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/Relations/BelongsToManyKeys.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,12 @@ public function initRelation(array $models, $relation)
104104
public function match(array $models, Collection $results, $relation)
105105
{
106106
$dictionary = $this->buildDictionary($results);
107-
107+
108108
foreach ($models as $model) {
109109
foreach ($this->localKeys as $localKey) {
110110
$key = $model->getAttribute($localKey);
111-
if (
112-
isset($dictionary[$key])
113-
) {
111+
if (isset($dictionary[$key]))
114112
$model->setRelation($this->relations[$localKey], $dictionary[$key]);
115-
}
116113
}
117114
$model->unsetRelation($relation);
118115
}

src/Relations/HasManyKeys.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ public function addConstraints(): void
7171
}
7272
}
7373

74-
/**
75-
* Get the key value of the parent's local key.
76-
* Info: From HasOneOrMany class.
77-
*
78-
* @return mixed
79-
*/
80-
public function getParentKey()
81-
{
82-
return $this->parent->getAttribute($this->localKey);
83-
}
84-
8574
/**
8675
* Set the constraints for an eager load of the relation.
8776
* Note: Used to load relations of multiple models at once.
@@ -158,6 +147,17 @@ protected function buildDictionary(Collection $models): array
158147
return $dictionary;
159148
}
160149

150+
/**
151+
* Get the key value of the parent's local key.
152+
* Info: From HasOneOrMany class.
153+
*
154+
* @return mixed
155+
*/
156+
public function getParentKey()
157+
{
158+
return $this->parent->getAttribute($this->localKey);
159+
}
160+
161161
/**
162162
* Get the results of the relationship.
163163
*

0 commit comments

Comments
 (0)