Example #1
0
 /**
  * @return null
  */
 public function flush()
 {
     $result = null;
     $columns = $this->toDBArray();
     if ($this->id) {
         $result = $this->db->update($this->getTableName(), $columns, $this->getDBColumns(), array("id" => $this->id));
         if ($this->db->affectedRows() <= 0) {
             if ($this->db->createQuery($this->getTableName())->find("`id`")->where("`id`=:id")->execute(array("id" => $this->id))->findRow() <= 0) {
                 $result = $this->db->insert($this->getTableName(), $columns, $this->getDBColumns());
                 $this->id = $this->db->lastId();
             }
         }
     } else {
         $result = $this->db->insert($this->getTableName(), $columns, $this->getDBColumns());
         $this->id = $this->db->lastId();
     }
     return $result;
 }