Skip to content

Commit 8021452

Browse files
Merge pull request #46 from gearbox-solutions/fix-hasone-hasmany-null
Fix hasone hasmany null
2 parents 38ffe8b + 1592c2e commit 8021452

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Database/Eloquent/Relations/HasMany.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ public function addConstraints()
1919
}
2020
}
2121

22+
protected function getKeys(array $models, $key = null)
23+
{
24+
return collect($models)->map(function ($value) use ($key) {
25+
return $key ? $value->getAttribute($key) : $value->getKey();
26+
})->values()->filter()->unique(null, true)->sort()->all();
27+
}
28+
2229
}

src/Database/Eloquent/Relations/HasOne.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ public function addConstraints()
1717
$this->query->where($this->foreignKey, '==', $this->getParentKey());
1818
}
1919
}
20+
21+
protected function getKeys(array $models, $key = null)
22+
{
23+
return collect($models)->map(function ($value) use ($key) {
24+
return $key ? $value->getAttribute($key) : $value->getKey();
25+
})->values()->filter()->unique(null, true)->sort()->all();
26+
}
2027
}

0 commit comments

Comments
 (0)