I have a mysql table like this:
CREATE TABLE testtbl (
id INT(11) NOT NULL AUTO_INCREMENT,
field1 INT(11) NOT NULL DEFAULT '0',
field2 INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
);
INSERT INTO testtbl (field1, field2) VALUES (1, 1);
My Model is :
class Testtbl extends \Phalcon\Mvc\Model
{
public $id;
public $field1;
public $field2;
public function initialize() {
$this->setConnectionService('db');
$this->skipAttributes(array('field1'));
}
public function columnMap() {
return array(
'id' => 'id',
'field1' => 'field1',
'field2' => 'field2'
);
}
}
In my controller i have
$model = new Testtbl();
$model->id=1;
$model->field2 = 2;
if ($model->update() === false) {
$msg = $model->getMessages();
print_r($msg);
}
The db service is set to log the queries in a file. After executing the controller's code the log file contains:
[Sun, 19 Jan 14 13:05:47 +0000][INFO] DESCRIBE testtbl
[Sun, 19 Jan 14 13:05:47 +0000][INFO] SELECT COUNT(*) "rowcount" FROM testtbl WHERE id = ?
[Sun, 19 Jan 14 13:05:47 +0000][INFO] UPDATE testtbl SET field2 = ? WHERE id = ?
Why is there a select before the update ? How can i make the update without any prior select ? (if i update a model received from findFirst, there wont be any SELECT COUNT(*) "rowcount" .. in the log, it appears only when i make an update directly.)
I am using setReadConnectionService('slave server') and setWriteConnectionService('master') in the model. Am i correct to assume that if the slave server is behind the master (lags for whatever reason), the updates will be forever lost as they won't be in the replication binlog ?