node.js - sequelize 交易中的 setShooter 是什么?

标签 node.js transactions sequelize.js

user.setShooter 会在这里做什么?

return sequelize.transaction(function (t) {

  // chain all your queries here. make sure you return them. <br>
  return User.create({<br>
    firstName: 'Abraham',<br>
    lastName: 'Lincoln'<br>
  }, {transaction: t}).then(function (user) {<br>
    return user.setShooter({<br>
      firstName: 'John',<br>
      lastName: 'Boothe'<br>
    }, {transaction: t});<br>
  });<br>
<br>
}).then(function (result) {<br>
  // Transaction has been committed<br>
  // result is whatever the result of the promise chain returned to the transaction callback<br>
}).catch(function (err) {<br>
  // Transaction has been rolled back<br>
  // err is whatever rejected the promise chain returned to the transaction callback<br>
});<br>

最佳答案

setShooter 只不过是某个 Sequelize 模型类中的一个函数

例如

import Sequelize from 'sequelize'

export default class Product extends Sequelize.Model {

    // model init
    static init(sequelize) {
        return super.init({
                name: { type: Sequelize.STRING(128), allowNull: false },
                description: { type: Sequelize.TEXT, allowNull: false }
            },
            {
                sequelize,
                tableName: 'c_products'
            })
    }

    setShooter() {
        console.log('Hello World!')
    }

}

关于node.js - sequelize 交易中的 setShooter 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51308700/

相关文章:

c# - 在嵌套方法中实现嵌套事务的方法

mysql - Spring Hibernate MySQL 测试不回滚

iphone - 我应该相信 SQLite 事务以避免文件损坏吗?

javascript - 无法使用非对象作为目标或处理程序创建代理

javascript - 在 Node js 中读取 PDF 文件

node.js - 从 npm 脚本运行 babel-cli 不起作用

node.js - 序列化,在边界框内搜索点

javascript - Sequelize 包含联结表中的属性

node.js - Axios + Sequelize ValidationError = Promise catch block 中没有请求或响应对象?如何处理?

javascript - 静态函数继承