A big thank you, bro. I was getting crazy (believe you or not) for already more than 6 months trying to understand how this works and how to apply it. Finally I could create this association.
Well done! It's a bit complicated...especially the Many-to-Many relationships but I think you did a good job. Thanks for taking the time to make this video. Cheers.
Hey men, im struggling a lot with a big API project that im developing. In this video, you use asociations between tables that are created by a const. Usign sequelize-CLI, every time that you create a new model, a new file is created and the asociations are declared in a static associate(models) {}. Its too dificult to explain doing associations by that method? Or maybe make a video about it?
@@WebDevJourney Yes, im sorry, my english isn't so good lol. I think you create the sequelize/models manually. When using Sequelize-CLI to create models, the associatios have a little different sintax. In my project, I have created the migrations files with the foreings keys associated columns and tables, but, when I wrote the associations in models file, things are quite different and having some errors of type "ForeignKeyConstraintError"
@@MegaGian2009 I found this levelup.gitconnected.com/creating-sequelize-associations-with-the-sequelize-cli-tool-d83caa902233 Let me know if it helps if not ill try to make a video around this
@@WebDevJourney i think i already read that post, it was posted before sequelize v6 launch. So, the models creations are different. Using the same logic structure of a one-to-Many associations don't work using sequelize v6.
I did an easier version of the code, kind of makes aa dirty model loading but in the end it's cleaner... Anyway TYSM I got so lost in the explanation I was given :c
Thank you for this video :), how to do with 3 tables, users, posts, comments ? 1 user has multiple posts, 1 post has only one user, 1 post has multiple comments, 1 user has multiple comments, 1 comment has only one user
I found how to do it, in file user i add : User.belongsToMany(models.Post, { through: "Comments" }); and in file post i add : Post.belongsToMany(models.User, { through: "Comments" }) in folder migrations in file comment : i add that : userId: { type: Sequelize.INTEGER, references: { model:{ tableName: "Users" }, key: "id" }, allowNull: false }, postId: { type: Sequelize.INTEGER, references: { model:{ tableName: "Posts" }, key: "id" }, allowNull: false
hmm I still dont get it in many-to-many relationship, why when user "wdj" followed "tom" the code say wdj.addUser(tom), isn't that should be wdj.addFollow(tom) ? assuming const wdj = user.findOne({where: {name: "wdj"}}) and const tom = user.findOne({where:{name: "tom"}})
A big thank you, bro. I was getting crazy (believe you or not) for already more than 6 months trying to understand how this works and how to apply it. Finally I could create this association.
awesome to hear that, good to know my videos are helping others!
@@WebDevJourney love from pakistan
Okay I know this is a loooong video. But hopefully you learned something because if not, well you need to watch the video again.
Hi, simply wanted to thank you for your videos.. watched the entire playlist. You have a great teaching style!
It took me 2 months to find a video like this 💯 Great Tutorial
Very nice explanation, I was struggling to understand how many-to-many worked, and now I get it :D
Excelent explanation!! very clear and easy to follow through!
Excelent comment!! very clear and easy to follow through!
Well done! It's a bit complicated...especially the Many-to-Many relationships but I think you did a good job. Thanks for taking the time to make this video. Cheers.
Thank you for existing
Keep up the good work! Would be nice to see some database designs on real world problems. Thanks for your videos!
thank you so much bro, you made it to easy to understand!❤
You did great man, I understood well about the relations and special magic methods.
"Dude I hate when my printer just starts to update on it's own. It gives me the jumps."
LOL that was so random but funny.
Wow! Best explanation ever! You really do a great job!
Btw, I love the part 39:01 "I don't have friends" XD I hope you were joking!
Thank you so much sir!
very well explained, thank you
You save a life bro!!! Thank you.
Very useful mate! Thank you for this tutorial
Awesome explanations thanks dude
Excelent tutorial, thanks man!
Nice video. I was wondering what extension you are using to draw on your screen?
its not an extension it's a software called epic pen and the best part is its free epic-pen.com/
@@WebDevJourney thank you so much
A big thank you, bro.
Hey great tutorial! How could we do that but having the models in separated files? Sequelize throws an error
Very well explained!
its really a great video...thanks alot
i faced this issue : "createdUser.addRole is not a function", if i remove as: from the Role association option, then it works fine. what to do???
Very resourceful
What is the VSC extension you use to draw on screen? That's super cool!
its not an extension it's a software called epic pen and the best part is its free epic-pen.com/
thank you sir, it helps me
pls i have an issue,
how do i do the relatioship if all my models are in different files
You would need to export then import where needed then do the link.
Any link for the project code?
Thank you
Anyone facing issue with hasMany association as its returning only return one record😕😕😕😕
Hey men, im struggling a lot with a big API project that im developing. In this video, you use asociations between tables that are created by a const. Usign sequelize-CLI, every time that you create a new model, a new file is created and the asociations are declared in a static associate(models) {}. Its too dificult to explain doing associations by that method? Or maybe make a video about it?
trying to understand your question. You want to know how to create associations using the Sequelize-CLI?
@@WebDevJourney Yes, im sorry, my english isn't so good lol. I think you create the sequelize/models manually. When using Sequelize-CLI to create models, the associatios have a little different sintax.
In my project, I have created the migrations files with the foreings keys associated columns and tables, but, when I wrote the associations in models file, things are quite different and having some errors of type "ForeignKeyConstraintError"
@@MegaGian2009 I found this levelup.gitconnected.com/creating-sequelize-associations-with-the-sequelize-cli-tool-d83caa902233
Let me know if it helps if not ill try to make a video around this
@@WebDevJourney i think i already read that post, it was posted before sequelize v6 launch. So, the models creations are different. Using the same logic structure of a one-to-Many associations don't work using sequelize v6.
@@MegaGian2009 then I will try to do a video on that when I have the time, Sorry that I can not do it faster
I did an easier version of the code, kind of makes aa dirty model loading but in the end it's cleaner... Anyway TYSM I got so lost in the explanation I was given :c
Thank you for this video :), how to do with 3 tables, users, posts, comments ? 1 user has multiple posts, 1 post has only one user, 1 post has multiple comments, 1 user has multiple comments, 1 comment has only one user
I found how to do it, in file user i add : User.belongsToMany(models.Post, { through: "Comments" }); and in file post i add : Post.belongsToMany(models.User, { through: "Comments" }) in folder migrations in file comment : i add that :
userId: {
type: Sequelize.INTEGER,
references: {
model:{
tableName: "Users"
},
key: "id"
},
allowNull: false
},
postId: {
type: Sequelize.INTEGER,
references: {
model:{
tableName: "Posts"
},
key: "id"
},
allowNull: false
Hey, is there a source code that i can possibly look at?
here you go github.com/webdevjourneyWDJ/postgres_sequelize
thank you broo
Tried to undo this 1 unlike by liking and subscribing
4:10 one to one
hmm I still dont get it in many-to-many relationship, why when user "wdj" followed "tom" the code say wdj.addUser(tom), isn't that should be wdj.addFollow(tom) ? assuming const wdj = user.findOne({where: {name: "wdj"}}) and const tom = user.findOne({where:{name: "tom"}})