From a7b7d3bd91cbc8598511f8350213d021c6b1fc14 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Mon, 9 Nov 2015 23:06:10 -0200 Subject: [PATCH] Fixes relation name for belongsTo. refs #278 --- src/Ardent/Ardent.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Ardent/Ardent.php b/src/Ardent/Ardent.php index 22d564e..eb5aa53 100755 --- a/src/Ardent/Ardent.php +++ b/src/Ardent/Ardent.php @@ -401,9 +401,12 @@ public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relat // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. if (is_null($relation)) { - $backtrace = debug_backtrace(false); - $caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1]; - $relation = $caller['function']; + $backtrace = debug_backtrace(false, 4); + if ($backtrace[1]['function'] == 'handleRelationalArray') { + $relation = $backtrace[1]['args'][0]; + } else { + $relation = $backtrace[3]['function']; + } } if (is_null($foreignKey)) {