citusdata / citusdata/activerecord-multi-tenant

Reference data from multiple tenants in "activerecord-multitenant"

Open
#261 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Ruby
Stars
759
Forks
113
PR merge metrics
No merged PRs in 30d

Description

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.

```ruby
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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.