read from slave, then delete from master
shucream0117 opened this issue · 4 comments
shucream0117 commented
Hi.
First, record is read from slave.
(like this↓)
$user = Model::factory('User', 'slave')->find_one(1);
Second, I'd like to delete this record
$user->delete();
but, $user
has connection to "slave".
Is there any way to "read from slave, delete from master" ?
treffynnon commented
Use two queries. One for your primary DB and a second for your secondary DB.
shucream0117 commented
thank you for replying.
sorry, there was a mistake in my question. I modified sentence.
Is the way to "read from slave, delete from master"
like following?
$id = 1;
if (Model::factory('User', 'slave')->find_one($id)) { // read from slave
$user = Model::factory('User', 'master')->find_one($id); // find from master
$user->delete(); // delete from master
}
treffynnon commented
I think that looks about right.
shucream0117 commented
ok, thanks