REACT_FULLSTACK [6] Association in Sequelize

김병훈·2021년 9월 16일
0

REACT-FULLSTACK

목록 보기
6/10

In Server folder

I'm going to create another Table which is going to store that comment section

  • make Comments.js file in models folder (Commnets Table in TutorialDB)

  • copy Posts.js's code and paste all of this in Commnets.js

    The only thing that right now I should add to comments will be just the actual comment body.

  • and check in DB

  • there are Comments, and Posts table. and Comments table has only commentbody. Like I coded in VSCode

Posts.js (Server)

  • make code for associate with Comments tabel
Posts.associate = models => {
    Posts.hasMany(models.Comments, {
      onDelete: 'cascade',
    });
  };
  • drop the Comments tabel and then refresh VsCode,WorkBench
    • associate a comment to a post i am just going to add the id for the post which is id from Post Table

creating routes or endpoints are deal with comments

  • make a Comments.js in route folder (server)
  • import Posts.js 's statements at the top
const express = require('express');
const router = express.Router();

const { Comments } = require('../models'); 
// this is used to deal with the DB related to comments

module.exports = router;
// in order to make this router work, 
we need to export this at the bottom
because we need to export the router
containing all the endpoints that I'm going to
create related to this route

index.js (server)

  • inside of this folder so that in our index.js which is the file that like is the entry point of our server , I have to grab this route over here at the top

  • and then just apply new Router (Comments)
const commentsRouter = require('./routes/Comments');
app.use('/comments', commentsRouter);

  • now I have my comments route working in my application

create endpoints (Comments.js) server

  • ./routes/Comments
  • I want to grab only the comments related to specific id. But not the id for the comments . the id for the post
  • put some codes
router.get('/:postId', async (req, res) => {
  const postId = req.params.postId;
  const comments = await Comments.findAll({ where: { PostId: postId } });
  res.json(comments);
});

test in Postman

  • now, it sends an empty array but when I add more comments, it should return every single comments that exist for that specific post

for make comments as post request

  • send a body containing the text that is going to represent the comment , and also the postId that comment is related to.
  • grab object that im going to send through the body by saying (const comment = req.body),
  • accessing the comments model, and im going to create a new comment. await Comments.create(comment);
  • and at the end i can just return res.json(comment)
  • this is visual representation that this is working

post request in Postman

  • it returned my body which is exactly what i wrote
  • but, to get any confirmation go to comment table and check whether there is new comment or not
  • there is new comment what i send in Postman

get request after post request

profile
블록체인 개발자의 꿈을 위하여

31개의 댓글

comment-user-thumbnail
2022년 7월 29일

Hi companions my website webhostingsoffer. This site gives https://webhostingsoffer.com/ us relative data from facilitating and determines what is presented on hosting

답글 달기
comment-user-thumbnail
2022년 10월 31일

I see your post and read. This is good for me this is a good post you give a piece of great information and helpful thanks for sharing this page.
https://www.callgril.in/mumbai/
https://www.callgril.in/goa/
https://www.callgril.in/hyderabad/
https://www.callgril.in/bangalore/
https://www.callgril.in/lucknow/
https://www.callgril.in/delhi/

답글 달기
comment-user-thumbnail
2022년 11월 24일

In the event that you're trying to track down anybody to downsize your crushed, looking for a colleague to visit trade supper, or looking for a right hand to appear at a party or disco, then, at that point, our provocative call young ladies are dazing responsibility in each piece. Our thinking affiliations place each piece of our clients; guarantee that no appreciation is show from our decision. Here, pack is the unbelievably destroyed from ensure that you truly need to commit quality time close by your #1 call young lady.
https://www.adelhiescort.com/location/babarpur-escorts.html
https://www.adelhiescort.com/location/badarpur-escorts.html
https://www.adelhiescort.com/location/badli-escorts.html
https://www.adelhiescort.com/location/bahapur-escorts.html
https://www.adelhiescort.com/location/bakhtawarpur-escorts.html

답글 달기
comment-user-thumbnail
2022년 11월 24일

I was reliably seeing this blog, and I'm baffled! Astoundingly stunning data, particularly the last part, I care for such data a key arrangement. I was checking out at this specific data for quite a while. Considering this blog my appraisal has wrapped up.
https://www.adelhiescort.com/location/bawana-escorts.html
https://www.adelhiescort.com/location/begumpur-escorts.html
https://www.adelhiescort.com/location/bhajanpura-escorts.html
https://www.adelhiescort.com/location/bhalaswa-escorts.html
https://www.adelhiescort.com/location/bharat-nagar-escorts.html

답글 달기
comment-user-thumbnail
2022년 12월 3일

As a business owner, you need to make sure your association is up to date and effective. Associations can be a powerful wordle 2 tool for marketing your business, networking with potential customers, and building relationships with other businesses. But they can also be a challenge - especially if they're not up to date on current trends or if they don't have the latest technology.

답글 달기
comment-user-thumbnail
2023년 2월 13일
답글 달기
comment-user-thumbnail
2023년 3월 13일

Book Gurgaon calls girls to avail the hospitality for more zestful experience. https://www.dlfcallgirlsgurgaon.in/ go to the given link and enjoy it without any hindrance.

답글 달기
comment-user-thumbnail
2023년 4월 13일

We have a wide selection of uniquely incredible and juicy lists of incall or outcall escorts services for your particular night or day pleasure. https://www.callgirlsudaipur.com/ This choice can consist of a variety of sexy body parts that you see in the pictures and especially your erected dick. Our team and ladies will make sure that you are more than adequately satisfied with elite escorts and their professional capabilities.

답글 달기
comment-user-thumbnail
2023년 5월 5일

Under my delighting and overpowering body, you will turn out all of the joys you expected to have in your life. https://www.delhiescortservices.in/ I'm senselessly high into reputation as serving my relationship in a Russian escort young woman since I've seen a lot of captivating positions.

답글 달기
comment-user-thumbnail
2023년 5월 5일

We offer the best top entertainment with sexy escorts from different nations. You have an extensive choice between something more romantic up to some rough anal sex. https://www.poojaroy.in/ These are just some of the examples of the things that are possible whenever you desire to feel the right way and fully satisfied with the top class ladies.

답글 달기
comment-user-thumbnail
2023년 5월 24일

She is required to understand or read not just the mind but the body of the man also. Like actual food, even sex is termed as physical food. The interaction with the bold and beautiful s in will show a way of actually making the happening of hot romance possible.
https://www.jyotirawat.in/jamshedpur-call-girls.html
https://www.jyotirawat.in/sodala-call-girls.html
https://www.jyotirawat.in/sitapur-call-girls.html
https://www.jyotirawat.in/sanganer-call-girls.html
https://www.jyotirawat.in/salasar-call-girls.html

답글 달기
comment-user-thumbnail
2023년 6월 7일

You just want someone to talk to and not get too sexual https://www.callgirlsinkarolbagh.in/ that person. At times, a hearty conversation can be more soothing than anything. Our s can be your perfect companion. One of the best things about our s is that they are extremely educated and highly qualified. So, when you talk to them, you should know they have very good listening skills. Thus, you will feel very soothed when you talk to our girls. Our companionship service is the b

답글 달기
comment-user-thumbnail
2023년 7월 21일

We are the one and only choice for best escorts in with good reputation and discreet services. Here you got full satisfying adult entertainment service and genuine companionship through our sexy escorts girls. We can make memorable your tour, we have the best female escorts for casual dating, love, sex, adult meetings, role play and erotic massages.
https://www.sanakhan.in/bhimtal-call-girls.html
https://www.sanakhan.in/joshimath-call-girls.html
https://www.sanakhan.in/ramnagar-call-girls.html
https://www.sanakhan.in/chakrata-call-girls.html

1개의 답글
comment-user-thumbnail
2023년 7월 28일

Mumbai is such a spot to invest delightful energy, and you can fulfill yourself to an extreme level. Here at our Mumbai independent escort agency targets making your time significantly more https://www.nehamumbai.in/ delightful through independent call girls in Mumbai.

답글 달기
comment-user-thumbnail
2023년 7월 28일

Being one of the largest industrial centres, you will find many beautiful and willing escorts here to spend your time with. escorts are well trained and equipped to serve all your needs.

https://www.riyaescorts.in/
https://www.acallgirlsgurgaon.com/
https://www.callgirlsgurgaon.org/
https://www.escortservicegurgaon.site/
https://www.callgirlsgurgaon.online/
https://www.callgirlsgurgaon.fun/
https://www.callgirlsnavimumbai.in/

답글 달기
comment-user-thumbnail
2023년 8월 19일

If you are having any doubt regarding services, you can call us anytime or check out our girls’ profiles on-site. https://www.heenasehgal.in/panvel-call-girls.html

답글 달기
comment-user-thumbnail
2023년 10월 9일

Are you looking for gorgeous as well as sensational lady tonight? If of course, our Delhi escorts are always all set to be with you in your house/ hotel for an outstanding experience. The crackling hot call girls in Delhi are outstanding at various occasions and celebrations. https://www.escortsdelhi.in/ They can be your girlfriend as well as performer to bring excitement to the session.

답글 달기
comment-user-thumbnail
2023년 12월 2일

https://www.callgirlsuvidha.in/
https://www.callgirlsuvidha.in/delhi.html
https://www.callgirlsuvidha.in/amritsar.html
https://www.callgirlsuvidha.in/agra.html
https://www.callgirlsuvidha.in/ahmedabad.html
https://www.callgirlsuvidha.in/ajmer.html
https://www.callgirlsuvidha.in/ambala.html
https://www.callgirlsuvidha.in/aerocity.html
https://www.callgirlsuvidha.in/bangalore.html
https://www.callgirlsuvidha.in/bhubaneswar.html
https://www.callgirlsuvidha.in/chennai.html
https://www.callgirlsuvidha.in/coimbatore.html
https://www.callgirlsuvidha.in/mussoorie.html
https://www.callgirlsuvidha.in/haridwar.html
https://www.callgirlsuvidha.in/rishikesh.html
https://www.callgirlsuvidha.in/goa.html
https://www.callgirlsuvidha.in/guwahati.html
https://www.callgirlsuvidha.in/gurgaon.html
https://www.callgirlsuvidha.in/ghaziabad.html
https://www.callgirlsuvidha.in/hyderabad.html
https://www.callgirlsuvidha.in/faridabad.html
https://www.callgirlsuvidha.in/indore.html
https://www.callgirlsuvidha.in/jalandhar.html
https://www.callgirlsuvidha.in/jaipur.html
https://www.callgirlsuvidha.in/jaisalmer.html
https://www.callgirlsuvidha.in/jodhpur.html
https://www.callgirlsuvidha.in/kolkata.html
https://www.callgirlsuvidha.in/ludhiana.html
https://www.callgirlsuvidha.in/lucknow.html
https://www.callgirlsuvidha.in/manali.html
https://www.callgirlsuvidha.in/mumbai.html
https://www.callgirlsuvidha.in/instagram.html
https://www.callgirlsuvidha.in/vivastreet.html
https://www.callgirlsuvidha.in/indian-pornstar.html
https://www.callgirlsuvidha.in/skokka.html
https://www.callgirlsuvidha.in/locanto.html
https://www.callgirlsuvidha.in/visakhapatnam.html
https://www.callgirlsuvidha.in/allahabad.html
https://www.callgirlsuvidha.in/rajkot.html
https://www.callgirlsuvidha.in/ranchi.html
https://www.callgirlsuvidha.in/srinagar.html
https://www.callgirlsuvidha.in/jammu.html
https://www.callgirlsuvidha.in/dubai.html
https://www.callgirlsuvidha.in/nashik.html
https://www.callgirlsuvidha.in/jhansi.html
https://www.callgirlsuvidha.in/raipur.html
https://www.callgirlsuvidha.in/kanpur.html
https://www.callgirlsuvidha.in/bhopal.html
https://www.callgirlsuvidha.in/karnal.html
https://www.callgirlsuvidha.in/meerut.html
https://www.callgirlsuvidha.in/bikaner.html
https://www.callgirlsuvidha.in/gwalior.html
https://www.callgirlsuvidha.in/ujjain.html
https://www.callgirlsuvidha.in/thane.html
https://www.callgirlsuvidha.in/mahipalpur.html
https://www.callgirlsuvidha.in/mohali.html
https://www.callgirlsuvidha.in/mysore.html
https://www.callgirlsuvidha.in/noida.html
https://www.callgirlsuvidha.in/nagpur.html
https://www.callgirlsuvidha.in/navi-mumbai.html
https://www.callgirlsuvidha.in/panchkula.html
https://www.callgirlsuvidha.in/patiala.html
https://www.callgirlsuvidha.in/patna.html
https://www.callgirlsuvidha.in/pune.html
https://www.callgirlsuvidha.in/pathankot.html
https://www.callgirlsuvidha.in/surat.html
https://www.callgirlsuvidha.in/siliguri.html
https://www.callgirlsuvidha.in/udaipur.html
https://www.callgirlsuvidha.in/varanasi.html
https://www.callgirlsuvidha.in/kochi.html
https://www.callgirlsuvidha.in/vadodara.html
https://www.callgirlsuvidha.in/vijayawada.html
https://www.callgirlsuvidha.in/mount-abu.html
https://www.callgirlsuvidha.in/zirakpur.html
https://www.callgirlsuvidha.in/chandigarh.html
https://www.callgirlsuvidha.in/chandigarh-red-light-area.html
https://www.callgirlsuvidha.in/coimbatore-red-light-areas.html
https://www.callgirlsuvidha.in/red-light-areas-in-gurgaon.html
https://www.callgirlsuvidha.in/red-light-areas-in-guwahati.html
https://www.callgirlsuvidha.in/red-light-areas-in-gwalior.html
https://www.callgirlsuvidha.in/red-light-areas-in-jodhpur.html
https://www.callgirlsuvidha.in/red-light-areas-in-kota.html
https://www.callgirlsuvidha.in/red-light-areas-in-mysore.html
https://www.callgirlsuvidha.in/red-light-areas-in-raipur.html
https://www.callgirlsuvidha.in/red-light-areas-in-solapur.html
https://www.callgirlsuvidha.in/red-light-areas-in-hyderabad.html
https://www.callgirlsuvidha.in/red-light-area-in-mumbai.html
https://www.callgirlsuvidha.in/red-light-area-in-bangalore.html
https://www.callgirlsuvidha.in/red-light-areas-in-goa.html
https://www.callgirlsuvidha.in/red-light-areas-in-kolkata.html
https://www.callgirlsuvidha.in/red-light-areas-in-vijayawada.html

2개의 답글
comment-user-thumbnail
2024년 2월 3일

[url=https://slots-master.com/] Slots Master[/url]

답글 달기
comment-user-thumbnail
2024년 2월 3일

[url=https://slots-master.com/] Slots Master[/url]

답글 달기
comment-user-thumbnail
2024년 2월 3일

[url=https://slots-master.com/] Slots Master[/url]

답글 달기
comment-user-thumbnail
2024년 3월 22일

Her every parts are soft and clean that give a new joy to her client and when they start to love with her that time he never face any type of problem https://www.mansikalra.com/patna-escorts.html so Patna Escorts are care our her client joy and fun and she know all sex position and trick that help her to make you satisfied.

답글 달기
comment-user-thumbnail
2024년 3월 27일

#newapp
💧 Rummy nabob Apk 💧
🫠 Bonus : ₹51 🫠
🍁 Min. Withdraw : ₹100 🍁
🌐 Download Link 🔗
»https://rummynabob.cc

»https://rummy-nabob.xyz

#newapp
💧 Rummy golds Apk 💧
🫠 Bonus : ₹46 🫠
🍁 Min. Withdraw : ₹100 🍁
🌐 Download Link 🔗
»https://rummy-golds.cc

» https://rummy-golds.cc

#newapp
💧 Rummy modern Apk 💧
🫠 Bonus : ₹46 🫠
🍁 Min. Withdraw : ₹100 🍁
🌐 Download Link 🔗
»https://rummy-modern.cc

» https://rummy-modern.cc

#newapp
💧 Rummy go Apk 💧
🫠 Bonus : ₹51🫠
🍁 Min. Withdraw : ₹100 🍁
🌐 Download Link 🔗
»https://rummy-go.xyz

»https://rummy-go.xyz

#newapp
💧 Rummy loot Apk 💧
🫠 Bonus : ₹61🫠
🍁 Min. Withdraw : ₹100 🍁
🌐 Download Link 🔗
»https://rummy-loot.xyz
»https://rummy-loot.vip

»https://rummyloot.xyz

답글 달기