influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.66k stars 460 forks source link

Why are there two different ways to treat "excluded models" ? #555

Open kuzukuzu opened 6 years ago

kuzukuzu commented 6 years ago

Hi,

I have a question about the process of "excluded models".

I've read the initialization process, and noticed that process_excluded_model behaves different in each adapters.

mysql2 and postgres adapters process "excluded models" with prefixing table_name . On the other hand, other adapters (including abstract adapter) process them with calling establish connection .

I think former approach is better because of it's lightness. So the question is why are there two different ways to treat "excluded models" ?

mikecmpbll commented 5 years ago

i agree. the approaches were unified in my experimental branch. I'll be beginning to draw things across from that the next few weeks once we've confirmed that it's stable.

as it happens, i settled on the connection method. this way, the same separate connection is used for all excluded models (and it works with multi-host set ups).

domininik commented 5 years ago

There is a serious issue with prefixing table_name. ActiveRecord uses it here to get additional data while building WHERE queries. If proper association cannot be found and related data (which might include custom serialization) is missing, we end up with broken query. See related Rails issue https://github.com/rails/rails/issues/35839