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

Commit

Permalink
Fixes relation name for belongsTo. refs #278
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsantos07 committed Nov 10, 2015
1 parent 3b9d9ca commit a7b7d3b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit a7b7d3b

Please sign in to comment.