Up until this point, we've seen the _rev
key in our CouchDB documents, but we haven't had to actually use it in our application. In order for us to take any actions on an already existing document, we'll need to pass _rev
, along with _id
, to ensure that we are acting on the most recent document.
Let's prepare for this by adding a $_rev
variable to our base
class.
1. Open
classes/base.php
in your working directory, and add the$_rev
variable.abstract class Base { protected $_id; protected $_rev; protected $type;
2. Unfortunately, now anytime we call the
to_json
function,_rev
will always be included, regardless of it being used or not. If we were to send CouchDB anull _rev
, it would throw an error. So, let's add some code to theto_json
function inclasses/base.php
to unset our_rev
variable if it has no value set.public function to_json() { if (isset($this->_rev) === false) { unset($this->_rev); } return json_encode...