Open pbav opened 2 years ago
Feel free to make a PR
This does the trick:
from django_multitenant.models import TenantModel as TenantModelBase
class TenantModel(TenantModelBase):
class Meta:
abstract = True
# Access to related objects (specifically in prefetch_related) must use the tenant filter
base_manager_name = 'objects'
default_manager_name = 'objects'
The WHERE clause generated is just like
WHERE id IN (...)
prefetch_related
with thePrefetch
object works:This workaround sometimes helps, but, for example, it does not work with @django-auto-prefetch
P.S.
select_related
works as expected, it does filter by tenant.