@@ -131,6 +131,12 @@ public function getTable()
131
131
*/
132
132
public function hasOne ($ related , $ foreignKey = null , $ localKey = null )
133
133
{
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
+
134
140
$ foreignKey = $ foreignKey ?: $ this ->getForeignKey ();
135
141
136
142
$ instance = new $ related ;
@@ -150,6 +156,12 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
150
156
*/
151
157
public function hasMany ($ related , $ foreignKey = null , $ localKey = null )
152
158
{
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
+
153
165
$ foreignKey = $ foreignKey ?: $ this ->getForeignKey ();
154
166
155
167
$ instance = new $ related ;
@@ -170,6 +182,12 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
170
182
*/
171
183
public function belongsTo ($ related , $ foreignKey = null , $ otherKey = null , $ relation = null )
172
184
{
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
+
173
191
// If no relation name was given, we will use this debug backtrace to extract
174
192
// the calling method's name and use that as the relationship name as most
175
193
// 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
212
230
*/
213
231
public function belongsToMany ($ related , $ collection = null , $ foreignKey = null , $ otherKey = null , $ relation = null )
214
232
{
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
+
215
239
// If no relationship name was passed, we will pull backtraces to get the
216
240
// name of the calling function. We will use that function name as the
217
241
// title of this relation since that is a great convention to apply.
0 commit comments