Commit bf38285e authored by Jens Segers's avatar Jens Segers

Merge pull request #202 from Gabrola/belongsto_relation_fix

Fix belongsTo and belongToMany relations
parents 4ffc9be9 3c248001
...@@ -134,12 +134,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -134,12 +134,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/ */
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{ {
// Check if it is a relation with an original model.
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
{
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
}
// If no relation name was given, we will use this debug backtrace to extract // If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most // the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships. // of the time this will be what we desire to use for the relatinoships.
...@@ -149,6 +143,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -149,6 +143,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
$relation = $caller['function']; $relation = $caller['function'];
} }
// Check if it is a relation with an original model.
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
{
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
}
// If no foreign key was supplied, we can use a backtrace to guess the proper // If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which // foreign key name by using the name of the relationship function, which
...@@ -227,12 +227,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -227,12 +227,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/ */
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null) public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
{ {
// Check if it is a relation with an original model.
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
{
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
}
// If no relationship name was passed, we will pull backtraces to get the // If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the // name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply. // title of this relation since that is a great convention to apply.
...@@ -240,6 +234,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -240,6 +234,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
{ {
$relation = $this->getBelongsToManyCaller(); $relation = $this->getBelongsToManyCaller();
} }
// Check if it is a relation with an original model.
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
{
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
}
// First, we'll need to determine the foreign key and "other key" for the // First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query // relationship. Once we have determined the keys we'll make the query
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment