Laravel 4: Using whereHas() with HasManyThrough Relationships

I’ve discovered an issue with Eloquent in which using the whereHas() method with a HasManyThrough relationship returns the wrong results.

For instance, if I have the following model structure:

the following code will yield unexpected results:

I’ve sent a pull request to fix the issue but it needs to be discussed, so for now you can do use nested whereHas() calls like so:


  • T Karr

    Thanks, this is pretty handy, i’d just run across this myself and was wondering why it was comparing the wrong ids

  • Domenic Fiore

    Could you link to the PR? Curious to see the discussion.