更新数据
int Module_OOP_ORM_Data::update( )
int
$status 作用的行数public function update()
{
$data = $this->get_changed_data();
if ( !$data ) return 0;
$orm = $this->orm();
if ( !method_exists($orm, 'update') )
{
throw new Exception('当前ORM对象' . get_class($orm) . '不支持update方法');
}
$id_field = $this->get_id_field_name();
if ( $id_field )
{
$offset = current( $this->_get_offset_name_by_field($id_field) );
$where[$id_field] = $this->$offset;
}
else
{
throw new Exception('ORM:' . get_class($this) . '不存在ID字段,无法使用ORM系统自带的update方法更新。');
}
# 递增或递减数据处理
if ( $this->_value_increment && method_exists($orm->driver(), 'value_increment') ) foreach ( $this->_value_increment as $field=>$value )
{
# 如果存在递增或递减的数据
if ( isset($data[$field]) )
{
$orm->driver()->value_increment($field,$value);
unset($data[$field]);
}
}
$status = $orm->update($data, $where);
$this->_clear_changed_value_setting();
return $status;
}