8000 Testing SQL relations · mongodb/laravel-mongodb@765e667 · GitHub
[go: up one dir, main page]

Skip to content

Commit 765e667

Browse files
committed
Testing SQL relations
1 parent 2692777 commit 765e667

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ public function getTable()
131131
*/
132132
public function hasOne($related, $foreignKey = null, $localKey = null)
133133
{
134+
// Check if it is a relation with an original model.
135+
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
136+
{
137+
return parent::hasOne($related, $foreignKey, $localKey);
138+
}
139+
134140
$foreignKey = $foreignKey ?: $this->getForeignKey();
135141

136142
$instance = new $related;
@@ -150,6 +156,12 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
150156
*/
151157
public function hasMany($related, $foreignKey = null, $localKey = null)
152158
{
159+
// Check if it is a relation with an original model.
160+
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
161+
{
162+
return parent::hasMany($related, $foreignKey, $localKey);
163+
}
164+
153165
$foreignKey = $foreignKey ?: $this->getForeignKey();
154166

155167
$instance = new $related;
@@ -170,6 +182,12 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
170182
*/
171183
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
172184
{
185+
// Check if it is a relation with an original model.
186+
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
187+
{
188+
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
189+
}
190+
173191
// If no relation name was given, we will use this debug backtrace to extract
174192
// the calling method's name and use that as the relationship name as most
175193
// of the time this will be what we desire to use for the relatinoships.
@@ -212,6 +230,12 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
212230
*/
213231
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
214232
{
233+
// Check if it is a relation with an original model.
234+
if (!is_subclass_of($related, 'Jenssegers\Mongodb\Model'))
235+
{
236+
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
237+
}
238+
215239
// If no relationship name was passed, we will pull backtraces to get the
216240
// name of the calling function. We will use that function name as the
217241
// title of this relation since that is a great convention to apply.

0 commit comments

Comments
 (0)
0