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. EMMA 覆盖率工具

    1. EMMA 介绍 EMMA 是一个开源.面向 Java 程序测试覆盖率收集和报告工具.它通过对编译后的 Java 字节码文件进行插装,在测试执行过程中收集覆盖率信息,并通过支持多种报表格式对覆盖率 ...

  2. excel之工作表工作簿保护暴力撤销

    excal之工作表工作簿保护暴力撤销 excel可以在审阅中设置工作表.工作簿的密码保护,但是当密码忘记或一些特殊情况下需要进行操作. 1.工作簿保护撤销 步骤一:将需要破解的excal文件后缀名改为 ...

  3. 【源码阅读】Java集合之三 - ArrayDeque源码深度解读

    Java 源码阅读的第一步是Collection框架源码,这也是面试基础中的基础: 针对Collection的源码阅读写一个系列的文章,本文是第三篇ArrayDeque. ---@pdai JDK版本 ...

  4. 我的Linux之路——windows10用WMware安装CentOS6.9 虚拟机详细步骤

    出自:http://blog.51cto.com/13438667/2059926 一.安装环境 windows10操作系统物理机VMware Workstation 软件(可以在网上下载)CentO ...

  5. WPF 动态创建 DataTemplate 及数据绑定

    WPF 动态创建 DataTemplate 及数据绑定 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-22 参考: star ...

  6. C# XML文件读取

    using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; usin ...

  7. C# 发送和接受Get请求

    1.发送Get请求 public static string HttpGet(string Url, string postDataStr) { HttpWebRequest request = (H ...

  8. 认识Echarts(网址:http://echarts.baidu.com/tutorial.html#ECharts%20%E7%89%B9%E6%80%A7%E4%BB%8B%E7%BB%8D)

    first.html: <!DOCTYPE html><html lang="en"><head> <meta charset=" ...

  9. Spring Data JPA + layui的前台分页插件layPage实现页面的分页

    一.后台代码: 1.1 controller层代码 @RequestMapping("/xxxxxx") public String showInformationCode(Str ...

  10. 使用CocoaPods卡在了"pod setup"界面的解决办法

      http://blog.csdn.net/samoy/article/details/51956799   有时候,我们在执行pod install或pod search命令时,会在终端偶现卡在’ ...