Skip to content

Update QueryBuilder get method to run getFresh method #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2015
Merged

Update QueryBuilder get method to run getFresh method #619

merged 1 commit into from
Oct 15, 2015

Conversation

loonytoons
Copy link
Contributor

Following the latest update of the laravel framework (5.1.20), the BaseQuery builder that used to just run the getFresh method (overriden by the mongodb child builder) in the get function, now calls the runSelect method that relies on the mysql Grammar object being present that this builder does not need to run.
This results in the error Call to a member function compileSelect() on null when trying to run a query.

This update simply removes the parent get() call and directly calls it's own getFresh method, thus return the functionality to what it was before the laravel update.

The particular change in laravel that causes this issue can be seen here:
laravel/framework@v5.1.19...v5.1.20#diff-cc3d43e01028390141596ae0da939930L1373

Fixes #618

Following the latest update of the laravel framework (5.1.20), the BaseQuery builder that used to just run the getFresh method (overriden by the mongodb child builder) in the get function, now calls the runSelect method that relies on the mysql Grammar object being present that this builder does not need to run.

This update simply removes the parent get() call and directly calls it's own getFresh method, thus return the functionality to what it was before the laravel update.
jenssegers added a commit that referenced this pull request Oct 15, 2015
Update QueryBuilder get method to run getFresh method
@jenssegers jenssegers merged commit b613933 into mongodb:master Oct 15, 2015
@jenssegers
Copy link
Contributor

Thanks!

@fuzonmedia
Copy link

Same issue facing .. "Fatal error: Call to a member function compileSelect() on null"
Using
"laravel/framework": "5.2.*",
"jenssegers/mongodb": "^3.0"

Can you help how to solve ?

@fuzonmedia
Copy link

I fixed it by changing the extends class from "Model" to "Eloquent" in my DB model

@ahmedash95
Copy link

ahmedash95 commented Jul 14, 2016

@fuzonmedia i'm facing this problem now but i can't understand which file you had change model to eloquent ?

@fuzonmedia
Copy link

@ahmedash95 you have to change it in your model file

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent {}

  • User is the laravel model

@ahmedash95
Copy link

@fuzonmedia okay i got it , but i change it in the Authenticate class in the laravel core itself and it works fine for me

@Ravaelles
Copy link

@ahmedash95 Because overriding core classes is always wrong as they will be overriden in the next Laravel upgrade via composer, I think it's a good idea to introduce new App\MongoUser class over which you have full control.
class MongoUser extends \Jenssegers\Mongodb\Eloquent\Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract { use Authenticatable, Authorizable, CanResetPassword; }

And then change your User model to:
class User extends MongoUser

That works for me 👍

@ahmedash95
Copy link

@Ravaelles thanks ^_^ 👍

@deanmcpherson
Copy link

For reference, I was getting the above error when using Cashier (User and Subscriptions are MySQL backed). The issue was because the default connection is set to mongo, the Cashier Models where looking in the wrong place.

I forked Cashier to fix, setting the connection direction on the subscription model.

@chintan13
Copy link

thanks to @Ravaelles

for some one new with same problem her is full Class:

<?php

namespace App;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class MongoUser extends Eloquent implements AuthenticatableContract, 
            AuthorizableContract, CanResetPasswordContract 
{ 
    use Authenticatable, Authorizable, CanResetPassword; 
}

and then

class User extends MongoUser

Works like a charm

I have used this with Laravel 5.3

mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this pull request Sep 2, 2024
Update QueryBuilder get method to run getFresh method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants