You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code works as expected and the call to multi_tenant :tenant automatically calls belongs_to :tenant and defines both tenant and tenant= methods.
the multi_tenant :tenant call does not automatically call belongs_to :tenant or define tenant and tenant= methods.
This is due to the implementation of tenant_klass_defined?
* fix logic inside the tenant_klass_defined method
* add tests for tenant_klass_defined?
* fix failed tests
* rubocop -a
* remove unnecessary word
* add a test case for the following
#105
* test a more appropriate class
* add multi_tenant
* Fixes rubocop warnings
---------
Co-authored-by: Gürkan İndibay <[email protected]>
The following code works as expected and the call to
multi_tenant :tenant
automatically callsbelongs_to :tenant
and defines bothtenant
andtenant=
methods.However, if both classes are inside a module
the
multi_tenant :tenant
call does not automatically callbelongs_to :tenant
or definetenant
andtenant=
methods.This is due to the implementation of
tenant_klass_defined?
so only the top-level constant
::Tenant
is expected to be the tenant class for tenant name:tenant
,::MyModule::Tenant
is not considered.I thought about copying Rails' implementation of
compute_type
https://github.com/rails/rails/blob/6ef39975d60cc9dafd1728c49e394dad11d12327/activerecord/lib/active_record/inheritance.rb#L224-L235
that in our example would search for the following 3 classes:
::MyModule::Foo::Tenant
,::MyModule::Tenant
,::Tenant
in that order.
Another solution would be to pass
class_name
just like we do in Rails.multi_tenant :tenant, class_name: "::MyModule::Tenant"
What do you guys think?
I'm willing to implement this if we can agree on a solution.
The text was updated successfully, but these errors were encountered: