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. Ubuntu13.10:密码忘记了怎么办?

    重启ubuntu系统,开机时长按shift按键进入GRUB菜单,选择第二个高级模式. 新版的UBUNTU系统居然启用了GRUNB2.0的内核!虽然传说相当的牛X,但是用起来感觉就是非常看不清楚字体,要 ...

  2. ansible自动化运维工具使用详解

    一. ansible 简介 1. ansible ansible是新出现的 自动化 运维工具 , 基于Python研发 . 糅合了众多老牌运维工具的优点实现了批量操作系统配置.批量程序的部署.批量运行 ...

  3. NFS共享权限问题

    //所有web集群节点的用户统一uid 例如888,用户最好也统一 Apache server: useradd -u 888 -s /sbin/nologin -M www chown -R www ...

  4. mysql 更改密码

    Mac 安装mysql时会生成一个默认密码: 这个可以在通知中找到,如果你需要更改密码则继续看下面, 今天给mac安装了MySQL,安装过程非常的顺利,但是在用一个可视化工具进行连接时,需要输入密码, ...

  5. Redis实战——简单介绍

    出自:https://www.cnblogs.com/moonlightL/p/7364107.html Redis简单介绍 Redis是一个开源,高级的键值存储和一个适用的解决方案,用于构建高性能, ...

  6. 【312】◀▶ arcpy 常用函数说明

    其他常用的 ArcPy 函数说明 序号 类名称   功能说明   语法 & 举例 01 RefreshActiveView   ====<<<< Description ...

  7. Ubuntu 15.04 开机无法进入图形界面,自动进入emergency mode解决方法

    原因:关机的时候没有正常退出,直接强制关机了... 解决: 就是在那个GIVE root password for maintenance (or type control-D to continue ...

  8. 用vim生成一批递增ID

    假设说要生成1000个以xxx开头的后面加数字的ID,比如xxx1到xxx1000.一般我们可以通过.csv去递增,然后替换,但是直接用vim也是可以达到这样的目的. 下面通过一个gif图演示这个过程 ...

  9. 【POJ1222】EXTENDED LIGHTS OUT

    参考博客 https://blog.csdn.net/so_so_y/article/details/76098713 题意 有一些灯泡组成了5*6的方阵.每个开关(开关会使灯泡的状态发生变化)除了控 ...

  10. Unity发布安卓Splash Image适应手机、平板

    问题描述: Unity发布安卓应用时,遇到只能添加一张SplashImage而需要适配手机及平板不同分辨率处理 解决方法: http://blog.csdn.net/aiyan1111111/arti ...