-
Notifications
You must be signed in to change notification settings - Fork 24
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
How to create a connection model? #90
Comments
Additionally if I have to, how do I at least force a model to always use a shard? on_shard(1) only works for the block syntax. How do I do that within a model? I want every request to go to the db defined for that shard/connection. |
@bluengreen, does it work ok if you do
I'm not totally sure what you're asking. Sounds like your databases are vertically partitioned maybe? ARS wasn't exactly designed for vertically partitioned DBs, much more designed around N shards with the same schema. I don't think it's out of the realm of possibility but might need a patch. |
@osheroff - no it doesn't work in the connection class or the concrete model. I tried to dig into the code more to find a work around, but didn't really see how the super class was being called. I can get it to work, sometimes, if I call establish_connection on the model directly.
However that is random, and times out. Another issue I found, is even when that does work, unless self.primary_key is set then .find and .last will not work. As for forcing a model to use a shard, I was thinking a work around could be to assign a model to a slave/shard and then forcing the model to always use that slave/shard.
Thanks for your help. Really would like to use this gem over others that are getting old, and not compatible with Rails 5. However, we have about 10 models that need to connect to other databases for lookup data and are not in the main schema. So its a necessity to be able to connect to other databases as we would normally under active record. |
I'm trying to create a connection to another database server using an abstract connection model like so:
This doesn't seem to work. The models that use this connection model are not connected to the other database, they are still using the main default db. I want to use this gem for the slaves and possibly the sharding but need to be able to establish a connection to another db. How do I do that using this gem? How do I connect to another database as I normally would do?
Thanks in advance
The text was updated successfully, but these errors were encountered: