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的更多相关文章

  1. 命令模式坚决svn树冲突(local unversioned, incoming add upon update)

    当工作目录修改删除过时更新使用svn更新就容易发生树冲突“Tree Confilict”.会出现类似提示. local unversioned, incoming add upon update 如果 ...

  2. 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 ...

  3. 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`.` ...

  4. 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 ...

  5. local unversioned, incoming add upon update问题

    当update的时候遇到如下问题 svn status D C ~/workspace/test/a.c > local unversioned, incoming add upon updat ...

  6. 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 ...

  7. svn: local unversioned, incoming file add upon update

    svn 文件冲突: D C 文件名 > local unversioned, incoming file add upon update svn revert 文件名 提示: 已恢复“文件名” ...

  8. 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 ...

  9. 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 ...

  10. 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 错误产生情景:我向一张带外键 ...

随机推荐

  1. azkaban平台的使用

    最近接触一些大数据的测试,有些hadoop/spark任务在服务器测试不太方便,会放到azkaban上跑 简单写下azkaband的使用流程:包括任务的上传和提交任务到hadoop集群 一 登陆azk ...

  2. Monkey测试工具介绍

    ---------------------------------------------------------------------------------------------------- ...

  3. 用Python将word文件转换成html(转)

    用Python将word文件转换成html   序 最近公司一个客户大大购买了一堆医疗健康方面的科普文章,希望能放到我们正在开发的健康档案管理软件上.客户大大说,要智能推送!要掌握节奏!要深度学习!要 ...

  4. Spring boot + Gradle + Eclipse打war包发布总结

    首先感谢两位博主的分享 http://lib.csdn.net/article/git/55444?knId=767 https://my.oschina.net/alexnine/blog/5406 ...

  5. Framework​Element.​Find​Name 根据名字查找控件

    WPF Framework​Element.​Find​Name 根据名字查找控件 运行环境:Window7 64bit,NetFramework4.7,C# 7.0, 编者:乌龙哈里 2017-10 ...

  6. Spring 学习记录8 初识XmlWebApplicationContext(2)

    主题 接上文Spring 学习记录7 初识XmlWebApplicationContext refresh方法 refresh方法是定义在父类AbstractApplicationContext中的. ...

  7. UNITY中使用不安全代码的相关设置

    必须执行以下三个步骤 1,在工程属性中设置:属性-生成-允许不安全代码 2,在Assets目录下增加 smcs.rsp(若打包设置中使用了.net 2.0 subset)或 gmcs.rsp(若打包设 ...

  8. 从零玩转JavaWeb系列7web服务器-----用户登录界面二维码的制作

    1.用eclipse工具新建一个Dynamic Web Project工程如下: 2.在Java Resources的src目录下新建一个包,包名称为com.it666.code 3.在com.it6 ...

  9. java算法 蓝桥杯 摆花

    问题描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...

  10. 高性能Web服务器Nginx的配置与部署研究(13)应用模块之Memcached模块+Proxy_Cache双层缓存模式

    通过<高性能Web服务器Nginx的配置与部署研究——(11)应用模块之Memcached模块的两大应用场景>一文,我们知道Nginx从Memcached读取数据的方式,如果命中,那么效率 ...