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

NoDynamicWhereRule fails when scope is called in another class #185

Open
owenvoke opened this issue Jan 22, 2024 · 0 comments
Open

NoDynamicWhereRule fails when scope is called in another class #185

owenvoke opened this issue Jan 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@owenvoke
Copy link
Contributor

This is something we've been experiencing for a while, but have tended to just baseline the errors.

The issue is as mentioned to you. I've attached an example below, to demonstrate the issue:

class Account extends Model
{
    public function actions(): HasMany
    {
        return $this->hasMany(AccountAction::class);
    }

    public function hasActiveActions(): bool
    {
        // There will be a failure here, as it appears to be checking for `scopeWhereActive()` on this class, rather than on the relationship model.
        return $this->actions()->whereActive()->exists();
    }
}

class AccountAction extends Model
{
    public function scopeWhereActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }
}
@canvural canvural added the bug Something isn't working label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants