Since changing the database of a model object at runtime is not 
recommended.  What is the best way to create a read_only and writable 
connection, that should be used by models?  

I tried to use sharding, and ran into some errors changing the connection 
for the model.


1. How would I perform a Model.create using the "write" connection?

*1.a. [.set_server]*

*Model.set_server.create:*
NoMethodError:
       undefined method `set_server' for Models::Enrollees:Class


*Model.create.set_server: *(It appears the .set_server does not apply 
because it is called afterwards)
Sequel::DatabaseError:
       Mysql::Error: INSERT command denied to user 'readonly'@'localhost' 
for table 'enrollee'



*1.b. [.server]*

*Using Model.server.create:* (somehow it thinks the model is a dataset?)


tmp_ba = Models::Enrollees.server(:write_access).create(params)

 

*NoMethodError:*
*       undefined method `create' for 
#<Sequel::MySQL::Dataset:0x007ff4a158e0b0>*



*Using Model.create.server: *(It appears the .server does not apply because 
it is called afterwards)
Sequel::DatabaseError:
       Mysql::Error: INSERT command denied to user 'readonly'@'localhost' 
for table 'enrollee'



2. How do I do a Model.save? (Looks like I have to use 
model.set_server(:write_access).save)

I was able to get this to work by doing 
Model_instance.set_server(:write_access).save

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to