Skip to content
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

[5.4] withoutGlobalScopes is not works in eager loading if morphTo relation is used #18052

Closed
EligiusSantori opened this issue Feb 22, 2017 · 2 comments

Comments

@EligiusSantori
Copy link

EligiusSantori commented Feb 22, 2017

  • Laravel Version: 5.4.12
  • PHP Version: 7.0.14
  • Database Driver & Version: pdo_pgsql 7.0.14

Description:

There is no way to omit global scopes for morphTo relation.

Also the same problem is described here: https://laracasts.com/index.php/discuss/channels/general-discussion/remove-global-scope-on-morphto

Steps To Reproduce:

Schema::create('my_models', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('parent_id');
    $table->morphs('owner');
});

...

class MyModel extends Model {
    public function parent() { // Simple belongsTo relation
        $relation = $this->belongsTo(Parent::class);
        $relation->withoutGlobalScopes(); // Works fine
        return $relation;
    }
    public function owner() { // Simple morphTo relation
        $relation = $this->morphTo();
        $relation->withoutGlobalScopes(); // No effect
        return $relation;
    }
}

...

$model = MyModel::with('parent', 'owner')->first();
assert(!is_null($model->parent); // ok
assert(!is_null($model->owner); // fails if owner was filtered by any global scope
@Sweeeeep
Copy link

+1

1 similar comment
@pa-datpm
Copy link

+1

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

No branches or pull requests

3 participants