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. C 语言 - Unicode 解决中文问题

    问题: 打印一句中文 #include <stdio.h> int main() { char str[] = "你好,世界"; printf("%s\n&q ...

  2. 函数~匿名方法~lambda的逐渐过渡思想

    前提:基于委托实现 (1)使用函数名称 delegate void Printer(string s);//(1)申明委托 static void Main(string[] args) { //(3 ...

  3. ZooKeeper与仲裁模式

    为了让服务器之间可以通信,服务器间需要一些联系信息.理论上,服务器可以使用多播来发现彼此,但我们想让ZooKeeper集合支持跨多个网 络而不是单个网络,这样就可以支持多个集合的情况. 为了完成这些, ...

  4. 10分钟.Net Core 简单入门教程

    以 Centos 为例 1.安装所需的依赖关系 打开命令提示符并运行以下命令: sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/p ...

  5. iOS常用动画 类封装

    //这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...

  6. Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

    在Apache的配置文件 httpd.conf 中开启  LoadModule headers_module modules/mod_headers.so  即可解决这个问题.

  7. mysql varchar类型转换int类型

    select * from gyzd_yysinfo order by cast(yysid as SIGNED INTEGER) 或者 select * from gyzd_yysinfo orde ...

  8. Lenovo SplitScreen联想分屏软件只能在联想电脑运行,如何破解

    1.正常安装软件,重启电脑. 2.打开安装目录 C:\Program Files\Lenovo\Lenovo SplitScreen\SplitScreen 找到 MachineChecker.dll ...

  9. ShaderLab内置变量

    [ShaderLab内置变量]

  10. DDA算法

    [DDA算法] Digital Differential Analyzer,DDA算法是一种线段扫描转换算法.(线段光栅化算法) DDA算法优缺点: 1.消除了直线方程中的乘法计算,而在x.y方向使用 ...