add以及update
const addressData = {
name: this.post('name'),
mobile: this.post('mobile'),
province_id: this.post('province_id'),
city_id: this.post('city_id'),
district_id: this.post('district_id'),
address: this.post('address'),
user_id: this.getLoginUserId(),
is_default: this.post('is_default') === true ? 1 : 0
};
if (think.isEmpty(addressId)) {
addressId = await this.model('address').add(addressData);
} else {
await this.model('address').where({id: addressId, user_id: think.userId}).update(addressData);
}
// 如果设置为默认,则取消其它的默认
if (this.post('is_default') === true) {
await this.model('address').where({id: ['<>', addressId], user_id: think.userId}).update({
is_default: 0
});
}
const addressInfo = await this.model('address').where({id: addressId}).find();
return this.success(addressInfo);
第一:新增以及更新是做在一起的,通过对think.isEmpty(addressId)的判断
第二:整条记录的插入,是通过组装成数组
add以及update的更多相关文章
- 命令模式坚决svn树冲突(local unversioned, incoming add upon update)
当工作目录修改删除过时更新使用svn更新就容易发生树冲突“Tree Confilict”.会出现类似提示. local unversioned, incoming add upon update 如果 ...
- Error 'Cannot add or update a child row: a foreign key constraint fails故障解决
一大早的,某从库突然报出故障:SQL线程中断! 查看从库状态: mysql> show slave status\G Slave_IO_State: Waiting for master to ...
- insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.`productstatusrecord`, CONSTRAINT `p_cu` FOREIGN KEY (`cid`) REFERENCES `customer` (`cid`))错误
mybatis在insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.` ...
- IntegrityError at /admin/users/userprofile/add/ (1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_
报错现象 在执行 django 后台管理的时候添加数据导致 1452 错误 报错代码 IntegrityError at /admin/users/userprofile/add/ (1452, 'C ...
- local unversioned, incoming add upon update问题
当update的时候遇到如下问题 svn status D C ~/workspace/test/a.c > local unversioned, incoming add upon updat ...
- MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails
具体报错信息: Cannot add or update a child row: a foreign key constraint fails (`xxx`.`AAA`, CONSTRAINT `t ...
- svn: local unversioned, incoming file add upon update
svn 文件冲突: D C 文件名 > local unversioned, incoming file add upon update svn revert 文件名 提示: 已恢复“文件名” ...
- java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintV ...
- MySQL设置外键报错 #1452 - Cannot add or update a child row: a foreign key constraint fails 解决方法
MySQL数据库,当我尝试在A表中设置B表的主键为外键时,报出错误:#1452 - Cannot add or update a child row: a foreign key constraint ...
- Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails
错误: Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails 错误产生情景:我向一张带外键 ...
随机推荐
- Java8函数式接口和Lambda表达式
两者关系: Lambda表达式就是函数式接口(FunctionalInterface)实现的快捷方式,它相当于函数式接口实现的实例,因为在方法中可以使用Object作为参数,所以把Lambda表达式作 ...
- php switch
php switch switch用法类型与if,但是为了方便 不用写那么多个elseif.所以要判断 多个变量的时候我们可以使用switch <?php $email="admin& ...
- wx python
wx python 一. 下载和安装wxPython 1.1 下载 访问下载页面:http://wxpython.org/download.php即可. 要注意以下几点: 1. 如果是windows系 ...
- nginx代理socket tcp/udp
准备一台linux服务器.nginx官网:http://nginx.org/ .在网上搜到大致用的是 ngx_stream_core_module 这个模块,这里你也可以关注一下官方文档中的其他模块都 ...
- [Z]LaTeX入门教程
LaTeX入门教程 Contents TEX/LATEX是什么? 为什么要用TEX/LATEX? 安装 开始使用 数学符号使用中文文章的各个部分表格 行内公式与行间公式 上标与下标 常见的数学公式 行 ...
- TCP的交互数据流
在TCP进行数据传输时,可以分为成块数据流和交互数据流两种,如果按字节计算,成块数据与交互数据的比例约为90%和10%,TCP需要同时处理这两类数据,且处理的算法不同. 书籍本章中以Rlogin应用为 ...
- iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换. ...
- 一道容易栽坑的有趣的面试题(关于js,定时器,闭包等)
1.首先下面代码输出什么? for (var i = 0; i < 5; i++) { console.log(i); } 输出:0 1 2 3 4 2.上面只是普通的输出,没有陷阱再看下面这个 ...
- NormalMap & CubeMap
[NormalMap & CubeMap] 有时候我们需要CubeMap的环境反射也需要有凹凸信息,此时需要装将NormalMap与CubeMap结合. 因为要使用NormalMap,使用Pr ...
- Finite State Transducers
一, 简介 Finite State Transducers 简称 FST, 中文名:有穷状态转换器.在自然语言处理等领域有很大应用,其功能类似于字典的功能(STL 中的map,C# 中的Dictio ...