Skip to content

Commit e107901

Browse files
committed
fix for returning incorrect builder in hybrid relations
1 parent b9d99c6 commit e107901

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Jenssegers/Mongodb/Eloquent/HybridRelations.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Eloquent\Relations\MorphMany;
66
use Illuminate\Database\Eloquent\Relations\MorphOne;
77
use Illuminate\Support\Str;
8+
use Jenssegers\Mongodb\Eloquent\Builder;
89
use Jenssegers\Mongodb\Helpers\EloquentBuilder;
910
use Jenssegers\Mongodb\Relations\BelongsTo;
1011
use Jenssegers\Mongodb\Relations\BelongsToMany;
@@ -300,6 +301,10 @@ protected function guessBelongsToManyRelation()
300301
*/
301302
public function newEloquentBuilder($query)
302303
{
303-
return new EloquentBuilder($query);
304+
if (is_subclass_of($this, \Jenssegers\Mongodb\Eloquent\Model::class)) {
305+
return new Builder($query);
306+
} else {
307+
return new EloquentBuilder($query);
308+
}
304309
}
305310
}

tests/models/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
4+
use Jenssegers\Mongodb\Eloquent\HybridRelations;
45
use Illuminate\Auth\Authenticatable;
56
use Illuminate\Auth\Passwords\CanResetPassword;
67
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
@@ -9,6 +10,7 @@
910
class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract
1011
{
1112
use Authenticatable, CanResetPassword;
13+
use HybridRelations;
1214

1315
protected $connection = 'mongodb';
1416
protected $dates = ['birthday', 'entry.date'];

0 commit comments

Comments
 (0)