简体   繁体   中英

Rails 4 has_and_belongs_to_many with multi-tenancy (apartment)

I my application I use apartment to have multi-tenancy and postgresql, so each tenant is in a different schema.
I have a User model in public (schema) and a model Action in each tenant (schema).
I want to have a relation has_and_belongs_to_many between those two models.
It works fine if I disable multi-tenancy.

I have read on the apartment's site that habtm doesn't work because there is no model to exclude, but it's not my case. I don't want to exclude it. The relation table is in the tenant schema, with the model Action. Only User is declare to be excluded (so User is in public).

I have an error message saying PG::InvalidSchemaName: ERROR: schma « actions_public » doesn't exist.

How can I do ?

Thanks for any help.

I answer my on question.

Because of the design of Apartment, it's not possible to use a habtm relation when a model is excluded on the other one is not.
The solution is to use a has_many :through relation.
Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM