Creating instance with an association in Sequelize

后端 未结 8 1121
清酒与你
清酒与你 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:28

    Assuming you have the right association between users and login, you can just create a user including a login:

    User.create({
       name: "name",
       Login: {...}
    },{
       include: Login
    })
    

    you can find more information here: http://docs.sequelizejs.com/manual/tutorial/associations.html#creating-with-associations

提交回复
热议问题