framework: withoutGlobalScopes() ignored on HasManyThrough
- Laravel Version: 5.5.33 - 5.6.15
- PHP Version: 7.2
Description:
It seems like withoutGlobalScopes() and withoutGlobalScope() is ignored on HasManyThrough relations.
The query generated by the example below is:
SELECT
*
FROM
"comments"
INNER JOIN
"posts" ON "post"."id" = "comments"."post_id"
WHERE
"posts"."deleted_at" IS NULL
AND "posts"."user_id" = ?
But should be:
SELECT
*
FROM
"comments"
INNER JOIN
"posts" ON "post"."id" = "comments"."post_id"
WHERE
"posts"."user_id" = ?
Steps To Reproduce:
class User extends Model
{
public function comments()
{
return $this->hasManyThrough(Comment::class, Post::class)
->withoutGlobalScopes();
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 18 (12 by maintainers)
Almost two years later and there is still no way of doing this without using an external package 😕
Perhaps a better solution for this but this is how I got around this problem by extending the hasManyThrough relationship when I needed to extend the existing soft deletes trait and scope to work with a different database structure that doesnt use deleted_at columns with a timestamp
@yaim Your test scenario is different, the issue is about global scopes on the intermediate model.