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

Commit 8008885

Browse files
committed
Merge pull request #133 from bexarcreativeinc/master
Fix belongsTo() method to be compatible with Laravel 4.1.
2 parents e98ed2d + a601c3e commit 8008885

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/LaravelBook/Ardent/Ardent.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static function boot() {
225225
if (method_exists($myself, $method)) {
226226
$eventMethod = $rad.$event;
227227
self::$eventMethod(function($model) use ($method){
228-
return $model->$method();
228+
return $model->$method($model);
229229
});
230230
}
231231
}
@@ -353,9 +353,10 @@ public function __call($method, $parameters) {
353353
*
354354
* @param string $related
355355
* @param string $foreignKey
356+
* @param string $otherKey
356357
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
357358
*/
358-
public function belongsTo($related, $foreignKey = null) {
359+
public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relation = NULL) {
359360
$backtrace = debug_backtrace(false);
360361
$caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1];
361362

@@ -372,10 +373,12 @@ public function belongsTo($related, $foreignKey = null) {
372373
// for the related models and returns the relationship instance which will
373374
// actually be responsible for retrieving and hydrating every relations.
374375
$instance = new $related;
375-
376+
377+
$otherKey = $otherKey ?: $instance->getKeyName();
378+
376379
$query = $instance->newQuery();
377380

378-
return new BelongsTo($query, $this, $foreignKey, $relation);
381+
return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
379382
}
380383

381384
/**

0 commit comments

Comments
 (0)