Creating instance with an association in Sequelize

后端 未结 8 1023
清酒与你
清酒与你 2021-02-02 09:09

Using Sequelize, I\'ve created two models: User and Login.

Users can have more than one Login, but a login must have exactly one user, which me

8条回答
  •  独厮守ぢ
    2021-02-02 09:32

    As an extra you could also nest your creation to be even more effective and concise.

      // Set up the models
        var User = sequelize.define('User', {});
        var Login = sequelize.define('Login', {});
            ...
    
    
        User.create({
           name: "name",
           Login:
                {
                users: {..i.e several users if a user belongs to another user..}
                }
            },{
           include:{
          model: Login,
          include: User //nested model.Create
             }
        })
    

    as seen here: https://github.com/sequelize/sequelize/issues/7252

提交回复
热议问题