-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
tenantable_belongs_to method #340
base: master
Are you sure you want to change the base?
Conversation
32db5d1
to
d143bbf
Compare
…validates the tenant of the parent must be the same tenant of the record is defining the association
d143bbf
to
afed16a
Compare
@excid3 Hi, I hope you are very well. Can you review this PR please ? |
Hi @ptarud, what would be the difference with the already existing validation?
|
Dismiss my previous comment, I saw the difference, and actually found this useful for admin panels where there is no current_tenant. Thanks! |
When there is tenant setted and you change the tenant programmatically doing ActsAsTenant.current_tenant = other_tenant Take a look of this peace of code: ActsAsTenant.current_tenant = Tenant.first
t1_company = FactoryBot.create(:company)
ActsAsTenant.current_tenant = Tenant.second
t2_branch = FactoryBot.create(:branch, company: t1_company)
t1_company.inspect
=> "#<Company id: 1, tenant_id: 1, fantasy_name: \"Fantasy Name 1\", deleted: false, created_at: \"2024-09-06 15:58:45.439919000 +0000\", updated_at: \"2024-09-06 15:58:45.439919000 +0000\">"
t2_branch.inspect
=> "#<Branch id: 1, tenant_id: 2, company_id: 1, name: \"Branch 1\", time_zone: \"Etc/UTC\", deleted: false, created_at: \"2024-09-06 16:00:01.057926000 +0000\", updated_at: \"2024-09-06 16:00:01.057926000 +0000\">" I think is useful having a functionality for checking this behaviour. |
Hi @ptarud, what do you think about optionally auto-assigning the tenant id from the associated record? Just implemented it here, feel free to cherry pick: |
Add a tenantable_belongs_to class method that automatically validates that the parent association must has the same tenant than the record is defining the tenantable_belongs_to association.