Example #1
0
 /**
  * Updates an entity to the database
  * @param $obj
  */
 public function update($obj)
 {
     if ($this->isTransient($obj)) {
         throw new \InvalidArgumentException("Cannot update a transient entity");
     }
     foreach ($this->getOneToManyReferences($obj) as $oneToManyFields) {
         $this->handleOneToManyChanges($obj, $oneToManyFields);
     }
     if ($this->isDirty($obj)) {
         $query = $this->table->getUpdateSQL($obj);
         $this->runQuery($query);
         if (!mysqli_affected_rows($this->database->getMysqli()) > 0) {
             throw new \RuntimeException("No rows updated by update query! either row has been deleted or another version was committed");
         } else {
             //increment version
             $obj->{Dao::VERSION}++;
         }
     }
     $this->setCache($obj);
 }