Reputation: 11849
I use Apartment for multi-tenancy. Is there any way that I can run a query across all tenants instead of just my current one?
One kind of annoying way to do it would be something like
tenants.map do | tenant |
Apartment::Tenant.switch! tenant
User.all
end
I'm not sure what the side effects of switching tenants are though, and it would be nice if there was some way to set the tenant at a query level.
Upvotes: 3
Views: 2359
Reputation: 11849
One slightly better way of doing things is
tenants.map do | tenant |
Apartment::Tenant.switch(tenant) do
User.all
end
end
This way it's not changing the current tenant
Upvotes: 3