/** * 更新数据到数据库 * * @param Data $data * @param IStorage $storage * @access protected * @return integer affected row count */ protected function doUpdate(Data $data, IStorage $storage = null, $collection = null) { $record = $this->propsToRecord($data->toArray($only_dirty = true)); $meta = $this->getMeta(); $adapter = $storage ?: $this->getStorage(); $table_name = $collection ?: $meta->getCollection(); $primary_key = $meta->getPrimaryKey(); unset($record[$primary_key]); $primary_key = $adapter->qcol($primary_key); return $adapter->update($table_name, $record, "{$primary_key} = ?", $data->id()); }
/** * 更新一条数据 * * @param Data $data * @param IStorage $storage * @access protected * @return boolean */ protected function doUpdate(Data $data, IStorage $storage = null, $collection = null) { $meta = $this->getMeta(); $this->getStorage()->update($meta->getCollection(), array($meta->getPrimaryKey() => $data->id()), array('$set' => $this->propsToRecord($data->toArray())), array('safe' => true)); return true; }