@@ -134,12 +134,6 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
134134 */
135135 public function belongsTo ($ related , $ foreignKey = null , $ otherKey = null , $ relation = null )
136136 {
137- // Check if it is a relation with an original model.
138- if (!is_subclass_of ($ related , 'Jenssegers\Mongodb\Model ' ))
139- {
140- return parent ::belongsTo ($ related , $ foreignKey , $ otherKey , $ relation );
141- }
142-
143137 // If no relation name was given, we will use this debug backtrace to extract
144138 // the calling method's name and use that as the relationship name as most
145139 // of the time this will be what we desire to use for the relatinoships.
@@ -149,6 +143,12 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
149143
150144 $ relation = $ caller ['function ' ];
151145 }
146+
147+ // Check if it is a relation with an original model.
148+ if (!is_subclass_of ($ related , 'Jenssegers\Mongodb\Model ' ))
149+ {
150+ return parent ::belongsTo ($ related , $ foreignKey , $ otherKey , $ relation );
151+ }
152152
153153 // If no foreign key was supplied, we can use a backtrace to guess the proper
154154 // foreign key name by using the name of the relationship function, which
@@ -227,19 +227,19 @@ public function morphTo($name = null, $type = null, $id = null)
227227 */
228228 public function belongsToMany ($ related , $ collection = null , $ foreignKey = null , $ otherKey = null , $ relation = null )
229229 {
230- // Check if it is a relation with an original model.
231- if (!is_subclass_of ($ related , 'Jenssegers\Mongodb\Model ' ))
232- {
233- return parent ::belongsToMany ($ related , $ collection , $ foreignKey , $ otherKey , $ relation );
234- }
235-
236230 // If no relationship name was passed, we will pull backtraces to get the
237231 // name of the calling function. We will use that function name as the
238232 // title of this relation since that is a great convention to apply.
239233 if (is_null ($ relation ))
240234 {
241235 $ relation = $ this ->getBelongsToManyCaller ();
242236 }
237+
238+ // Check if it is a relation with an original model.
239+ if (!is_subclass_of ($ related , 'Jenssegers\Mongodb\Model ' ))
240+ {
241+ return parent ::belongsToMany ($ related , $ collection , $ foreignKey , $ otherKey , $ relation );
242+ }
243243
244244 // First, we'll need to determine the foreign key and "other key" for the
245245 // relationship. Once we have determined the keys we'll make the query
0 commit comments