示例#1
0
 /**
  * @param mixed $instance
  */
 public function save($instance)
 {
     $array = BinderObject::toArrayFrom($instance, true);
     $query = new Query();
     $query->table($this->mapper->getTable())->fields(array_keys($array));
     if (empty($array[$this->mapper->getPrimaryKey()]) || count($this->get($array[$this->mapper->getPrimaryKey()])) === 0) {
         $array[$this->mapper->getPrimaryKey()] = $this->insert($query, $array);
         BinderObject::bindObject($array, $instance);
     } else {
         $this->update($query, $array);
     }
 }