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

Reference data from multiple tenants in "activerecord-multitenant" #261

Open
osyo-manga opened this issue Oct 18, 2024 · 0 comments
Open

Comments

@osyo-manga
Copy link
Contributor

hi! I use this gem all the time, thanks!
By the way, I have a suggestion, could you please incorporate multi-tenant reference support into this gem?
The reason is that there is a case in which we need to acquire data across tenants, but we are having trouble achieving this with “activerecord-multitenant” at present.
To give a concrete example, we have a case where a group company is using an application and wants to be able to check data across multiple tenants in the group company.

The sample code is as follows.

tenant1, tenant2, tenant3 = Tenant.order(:created_at).take(3)
pp tenant1.id   # => "1310041a-c8a8-4d35-b395-8386af95a24f"
pp tenant2.id   # => "bb257a59-9811-473b-87a7-64c11f8799ab"
pp tenant3.id   # => "eff47159-53af-4b35-ba39-13e6fac0d5fa"

# Multiple `tenant1.id, tenant2.id, tenant3.id` queries are added
MultiTenant.with_read_multiple([tenant1.id, tenant2.id, tenant3.id]) do
  puts User.all.to_sql
  # => SELECT "users".*
  #      FROM "users"
  #     WHERE "users"."tenant_id" IN ('1310041a-c8a8-4d35-b395-8386af95a24f', 'bb257a59-9811-473b-87a7-64c11f8799ab', 'eff47159-53af-4b35-ba39-13e6fac0d5fa')
end

At this point, reading alone is sufficient, so we are not considering support up to writing

I'll make a PR if there is interest or acceptance of this proposal!

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

1 participant