Skip to content

undefined method getRelationWithoutConstraints() with v3.2.3 #1305

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

Closed
rimantoro opened this issue Sep 19, 2017 · 5 comments
Closed

undefined method getRelationWithoutConstraints() with v3.2.3 #1305

rimantoro opened this issue Sep 19, 2017 · 5 comments

Comments

@rimantoro
Copy link

When I'm updating Jenseggers MongoDB from v3.2.2 to v3.2.3, my test always return an error. Below is one of the error debug sample :

PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

E

Time: 390 ms, Memory: 16.00MB

There was 1 error:

1) InvalidPromoUsageTest::testInvalidMaxUsagePromo
BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::getRelationWithoutConstraints()

/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/illuminate/database/Query/Builder.php:2448
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/illuminate/database/Eloquent/Builder.php:1465
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php:28
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/illuminate/database/Eloquent/Builder.php:900
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/illuminate/database/Eloquent/Model.php:3551
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/vendor/illuminate/database/Eloquent/Model.php:3565
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/app/Models/Promo/Promo.php:418
/home/imanovski/www/sepulsa/meowth.sepulsa.dev/tests/promo/InvalidPromoUsageTest.php:1173

When I rollback to v3.2.2, everything is passed.

I'm debuging line-by-line then found something weird, because the method is not (or should not) related with MongoDB

public static function getByPromocode($code)
    {
        ### This line will raised error when using v3.2.3, but not in v3.2.2
        ### This a sample method from a model that didnt use Jensegger MongoDB
        $me = self::select('id')->whereHas('promocodes', function($q) use ($code) {
            $q->where('promocodes.code', $code);
        })->first();
        if($me) {
            return self::getById($me->id);
        } else {
            return null;
        }
    }

Does anybody have some issue and have the solution else than rollback to 3.2.2 ?

@HiradRoshandel
Copy link

I'm having the same problem

@ferulisses
Copy link

same problem here, downgrade to 3.2.2 works for me.

@NelinD
Copy link

NelinD commented Sep 25, 2017

http://joxi.ru/v29JYWWF3bdNDA this code call problem
Reproduced when using trait in a mysql model

@xarasbir
Copy link

Getting the same error. Rolling back to version 3.2.2 solves it.

@yinsee
Copy link

yinsee commented Jul 22, 2018

Here's how i managed to fix this in file:

vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php

<?php

namespace Jenssegers\Mongodb\Helpers;

...
use Illuminate\Database\Eloquent\Relations\Relation;
...

trait QueriesRelationships
{
    ...
    protected function getRelationWithoutConstraints($relation)
    {
        return Relation::noConstraints(function () use ($relation) {
            return $this->getModel()->{$relation}();
        });
    }

    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants