【问题标题】:what is setShooter in sequelize transaction?sequelize transaction 中的 setShooter 是什么?
【发布时间】:2018-12-20 20:46:18
【问题描述】:

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>

【问题讨论】:

    标签: node.js transactions sequelize.js


    【解决方案1】:

    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!')
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-13
      • 2021-11-03
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 2018-05-09
      • 2020-07-22
      • 2016-10-24
      • 2018-10-25
      相关资源
      最近更新 更多