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

Call allTenants() on a relationship #95

Open
warksit opened this issue Mar 16, 2018 · 1 comment
Open

Call allTenants() on a relationship #95

warksit opened this issue Mar 16, 2018 · 1 comment

Comments

@warksit
Copy link

warksit commented Mar 16, 2018

I would like to setup a relationship that returns allTenants() for a relationship. Is there a way to do that?

public function holidays() {
    // Correctly returns tenant scoped Holidays
    return $this->hasMany('Holidays');
}

public function allHolidays() {
    // Want all holidays not scoped
    return $this->hasMany('Holidays')->allTenants();
    // Fails as allTenants() needs to be called statically
}

Also tried

public function allHolidays() {
    // Want all holidays not scoped
    Holidays::allTenants();
    return $this->hasMany('Holidays');
    // No error but holidays are still scoped
}

I don't want to Tenant::disable() as I do still want everything else scoped.

@jbrooksuk
Copy link
Contributor

You can do:

public function allHolidays()
{
    return $this->hasMany('Holidays')->withoutGlobalScope('tenant_id');
}

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

2 participants