THE ****ING WALL
I've been pretty busy with all the coursework the past 2 weeks so I haven't been posting regularly...but here I am! At the beginning of week 2, we started on Flask + MySQL. For me, learning so much so quickly was a pretty big challenge. Now, in the beginning of using MySQL with Flask, it wasn't so bad. Everything is pretty straight forward because the query and the relationships between tables were very straight forward; 2 tables and either a one to one or a one to many relationship between them. Then came the Wall assignment. I think this is the first glimpse into future frustration with coding.
Wall wireframe:
Think of the Wall like a Facebook wall, you have a login/registration that goes into the user tables. When you log in, you can post multiple messages and on each message, you can post multiple comments. Here is the ERD:
So the login/registration part is straight forward because we've done it before. Having each user write messages is easy: you session the user id as they log in and input that user id into the messages table. So 80% of the assignment was basically done. All that was left was to get the comments. And this is the part where, looking back, I should've thought more about how to approach it rather than just start coding. I thought it'd be similar to the relationship between messages and users (and it is!) but I also had to pull out the message id so that the comments will display under the correct message.
That took me 4-5 hours to figure out. Looking back, I should've just tried to input an example comment with a message id that already exists and on MySQL, keep troubleshooting queries until I got the information that I wanted. So I began with getting all the comments with the message id;
Wall wireframe:
Think of the Wall like a Facebook wall, you have a login/registration that goes into the user tables. When you log in, you can post multiple messages and on each message, you can post multiple comments. Here is the ERD:
So the login/registration part is straight forward because we've done it before. Having each user write messages is easy: you session the user id as they log in and input that user id into the messages table. So 80% of the assignment was basically done. All that was left was to get the comments. And this is the part where, looking back, I should've thought more about how to approach it rather than just start coding. I thought it'd be similar to the relationship between messages and users (and it is!) but I also had to pull out the message id so that the comments will display under the correct message.
That took me 4-5 hours to figure out. Looking back, I should've just tried to input an example comment with a message id that already exists and on MySQL, keep troubleshooting queries until I got the information that I wanted. So I began with getting all the comments with the message id;
- SELECT comment, message FROM comments JOIN messages ON messages.id = comments.message_id WHERE messages.id = '{}'
- SELECT name, comment, message FROM comments JOIN messages on messages.id = comments.message_id JOIN users ON users.id = comments.user_id WHERE messages.id = '{}'
No comments:
Post a Comment