citusdata / django-multitenant

Python/Django support for distributed multi-tenant databases like Postgres+Citus
MIT License
712 stars 117 forks source link

TenantForeignKey FieldError when `tenant_id` is different #82

Closed silent-conspiracy closed 4 years ago

silent-conspiracy commented 4 years ago

Suppose the following models:

class Account(TenantModel):
  tenant_id = 'id'
  ...

class Project(TenantModel):
  tenant_id = 'account_id'
  ...

class Revenue(TenantModel):
  acc = models.ForeignKey(Account, ...)
  project = TenantForeignKey(Project, ...)
  tenant_id = 'acc_id'
  ...

When accessing revenue.project Django will throw:

django.core.exceptions.FieldError: Cannot resolve keyword 'acc_id' into field. Choices are: ...