Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit a7b7d3b

Browse files
committed
Fixes relation name for belongsTo. refs #278
1 parent 3b9d9ca commit a7b7d3b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Ardent/Ardent.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,12 @@ public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relat
401401
// foreign key name by using the name of the relationship function, which
402402
// when combined with an "_id" should conventionally match the columns.
403403
if (is_null($relation)) {
404-
$backtrace = debug_backtrace(false);
405-
$caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1];
406-
$relation = $caller['function'];
404+
$backtrace = debug_backtrace(false, 4);
405+
if ($backtrace[1]['function'] == 'handleRelationalArray') {
406+
$relation = $backtrace[1]['args'][0];
407+
} else {
408+
$relation = $backtrace[3]['function'];
409+
}
407410
}
408411

409412
if (is_null($foreignKey)) {

0 commit comments

Comments
 (0)