Skip to content

Sequelize Joining tables not created when using single create call with embedded object #13498

Discussion options

You must be logged in to vote

I got the correct combination working and added some better error logging.

    const userData =  { nameUser: 'test-name-2', Roles:[ {role:'admin'} ] };
    const options = { include: Role };

    // No join table is created. 
    const user = await User.create( userData, options );

So it looks like the part I didn't understand was that the create call wasn't going to create my UserRole table but instead create another Role entry. As the Role already existed, I was getting an error on must be unique. I am not sure if it is even possible to create the user table automatically when creating the user entry.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BradyLeach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant