1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\EloquentHasManyDeep; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Collection; |
|
|
|
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Relations\Concerns\SupportsDefaultModels; |
8
|
|
|
|
9
|
|
|
class HasOneDeep extends HasManyDeep |
10
|
|
|
{ |
11
|
|
|
use SupportsDefaultModels; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Get the results of the relationship. |
15
|
|
|
* |
16
|
|
|
* @return mixed |
17
|
|
|
*/ |
18
|
14 |
|
public function getResults() |
19
|
|
|
{ |
20
|
14 |
|
return $this->first() ?: $this->getDefaultFor(end($this->throughParents)); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Initialize the relation on a set of models. |
25
|
|
|
* |
26
|
|
|
* @param array $models |
27
|
|
|
* @param string $relation |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
6 |
|
public function initRelation(array $models, $relation) |
31
|
|
|
{ |
32
|
6 |
|
foreach ($models as $model) { |
33
|
6 |
|
$model->setRelation($relation, $this->getDefaultFor($model)); |
34
|
|
|
} |
35
|
|
|
|
36
|
6 |
|
return $models; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Match the eagerly loaded results to their parents. |
41
|
|
|
* |
42
|
|
|
* @param array $models |
43
|
|
|
* @param \Illuminate\Database\Eloquent\Collection $results |
44
|
|
|
* @param string $relation |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
6 |
|
public function match(array $models, Collection $results, $relation) |
48
|
|
|
{ |
49
|
6 |
|
if ($this->customEagerMatchingCallbacks) { |
|
|
|
|
50
|
2 |
|
foreach ($this->customEagerMatchingCallbacks as $callback) { |
51
|
2 |
|
$models = $callback($models, $results, $relation, 'one'); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
return $models; |
55
|
|
|
} |
56
|
|
|
|
57
|
4 |
|
$dictionary = $this->buildDictionary($results); |
58
|
|
|
|
59
|
4 |
|
foreach ($models as $model) { |
60
|
4 |
|
if (isset($dictionary[$key = $model->getAttribute($this->localKey)])) { |
61
|
4 |
|
$model->setRelation( |
62
|
4 |
|
$relation, |
63
|
4 |
|
reset($dictionary[$key]) |
64
|
4 |
|
); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
4 |
|
return $models; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Make a new related instance for the given model. |
73
|
|
|
* |
74
|
|
|
* @param \Illuminate\Database\Eloquent\Model $parent |
75
|
|
|
* @return \Illuminate\Database\Eloquent\Model |
76
|
|
|
*/ |
77
|
6 |
|
public function newRelatedInstanceFor(Model $parent) |
|
|
|
|
78
|
|
|
{ |
79
|
6 |
|
return $this->related->newInstance(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths