lundi 29 octobre 2018

Does hasManyThrough ignore global scopes on the intermediate table?

I have 3 tables: companies, games and tests.

  • Companies have many games
  • Games have many tests

The Game model has a global scope, which I can confirm is working:

public function apply(Builder $builder, Model $model)
{
    $builder->where('type', 'live');
}

Any direct queries I do using the Game model will only return results where the game type is set to "live".

I am using return $this->hasManyThrough('App\Test', 'App\Games') in my Company model to get all tests for a particular company.

However, this is returning results for all games, regardless of their type.

So I am wondering if using hasManyThrough bypasses the global scope that I've set in the Game model?

If so, is there any way around this? I want to make sure that all queries I'm doing are filtering out any games that aren't set to "live".

Cheers



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2EN3hAf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire