ardent icon indicating copy to clipboard operation
ardent copied to clipboard

belongsTo doesn't find right foreingKey

Open lamalab opened this issue 8 years ago • 3 comments

If foreingKey is not specified belongsTo doesn't find the right function to determine it. in version 3.0.0 this was the code:

$backtrace = debug_backtrace(false);
$caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1];
$relation = $caller['function'];

in the latest release (3.2.0) is:

if ($backtrace[1]['function'] == 'handleRelationalArray') {
    $relation = $backtrace[1]['args'][0];
} else {
    $relation = $backtrace[3]['function'];
}

As you can see, in 3.2.0 relase $backtrace[1] and backtrace[3] are inverted compared to the version 3.0.0 and this release works well. Inverting $backtrace[1] with $backtrace[3] works well.
Thanks ENx

lamalab avatar Dec 05 '15 19:12 lamalab

I do also getting problem on belongsTo if local_key is not specified. When calling associate function it trying to insert value to a column named call_id which doesn't available.

duongtdvn avatar Dec 21 '15 03:12 duongtdvn

I can confirm this issue.

ManiacTwister avatar Mar 22 '16 14:03 ManiacTwister

There is pull request with it: https://github.com/laravel-ardent/ardent/pull/295

pjona avatar Mar 09 '17 11:03 pjona