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

Commit

Permalink
Merge pull request #133 from bexarcreativeinc/master
Browse files Browse the repository at this point in the history
Fix belongsTo() method to be compatible with Laravel 4.1.
  • Loading branch information
igorsantos07 committed Dec 21, 2013
2 parents e98ed2d + a601c3e commit 8008885
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static function boot() {
if (method_exists($myself, $method)) {
$eventMethod = $rad.$event;
self::$eventMethod(function($model) use ($method){
return $model->$method();
return $model->$method($model);
});
}
}
Expand Down Expand Up @@ -353,9 +353,10 @@ public function __call($method, $parameters) {
*
* @param string $related
* @param string $foreignKey
* @param string $otherKey
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function belongsTo($related, $foreignKey = null) {
public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relation = NULL) {
$backtrace = debug_backtrace(false);
$caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1];

Expand All @@ -372,10 +373,12 @@ public function belongsTo($related, $foreignKey = null) {
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$instance = new $related;


$otherKey = $otherKey ?: $instance->getKeyName();

$query = $instance->newQuery();

return new BelongsTo($query, $this, $foreignKey, $relation);
return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
}

/**
Expand Down

0 comments on commit 8008885

Please sign in to comment.