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

Fix belongsTo() method to be compatible with Laravel 4.1. #133

Merged
merged 2 commits into from
Dec 21, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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