Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialA R
12,834 PointsSQLite foreign key matches - How to make it so a user can only update the courses they create?
Hi, I'm working on building out a full stack app, combining both Authentication: https://teamtreehouse.com/library/react-authentication
and Sequelize/Express routing:
https://teamtreehouse.com/library/using-sql-orms-with-nodejs
https://teamtreehouse.com/library/using-sequelize-orm-with-express
My current challenge is with foreign keys. Right now, I'm matching the User Name to the name of the post creator. I'd prefer to do this with foreign keys. It seems like getting the foreign key (named userId) back in a JSON is not possible.
Are there any resources available on a way to only allow users to update database entries they create, based on foreign keys? Is creating middleware in express a good option?
Thanks for any input!
1 Answer
moukim hfaidh
Full Stack JavaScript Techdegree Graduate 30,167 Pointshi , i was a bit confused too at first in using foreign keys with sequelize first you have to set the relationship between tables using hasMany or belongsTo then to answer your question in my opinion using a simple conditional statement is enough for this