Skip to content

Commit 1d8acce

Browse files
committed
Bugfix array_column false on empty items
1 parent aec1aa9 commit 1d8acce

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Traits/EntityTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public function __call(string $name, array $arguments)
161161
* @return mixed Function return is determined by the relation type and keysOnly:
162162
* array of items or keys (hasMany, manyToMany)
163163
* single item or key (belongsTo, hasOne)
164+
* null if no matches
164165
*/
165166
public function relations(string $tableName, $keysOnly = false)
166167
{
@@ -170,6 +171,12 @@ public function relations(string $tableName, $keysOnly = false)
170171
// Collapse to just this entity's relations
171172
$items = reset($items);
172173

174+
// Intercept empty results and force them to null
175+
if (empty($items))
176+
{
177+
return null;
178+
}
179+
173180
// Check the relationship to intercept singletons
174181
if ($this->_getRelationship($tableName)->singleton)
175182
{

0 commit comments

Comments
 (0)