Skip to content

Commit cf962df

Browse files
Miloslav Hůladg
authored andcommitted
Structure::getBelongsToReference() return value fix
1 parent a740e3f commit cf962df

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Database/Structure.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ public function getBelongsToReference(string $table, string $column = null): ?ar
148148

149149
if ($column) {
150150
$column = strtolower($column);
151-
return $this->structure['belongsTo'][$table][$column] ?? null;
151+
return isset($this->structure['belongsTo'][$table][$column])
152+
? [$this->structure['belongsTo'][$table][$column], $column]
153+
: null;
152154

153155
} else {
154156
return $this->structure['belongsTo'][$table] ?? [];

tests/Database/Structure.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ class StructureTestCase extends TestCase
173173
'tag_id' => 'tags',
174174
'book_id' => 'Books',
175175
], $this->structure->getBelongsToReference('books_x_tags'));
176+
177+
178+
Assert::same(
179+
['Books', 'book_id'],
180+
$this->structure->getBelongsToReference('books_x_tags', 'book_id')
181+
);
182+
183+
Assert::null($this->structure->getBelongsToReference('books_x_tags', 'non_exist'));
176184
}
177185

178186

0 commit comments

Comments
 (0)