In today's video, we'll take a break from all of the coding to look at how I've modeled out our entities in the database. I'll try to go over my thought process for each of the properties I've included in the FeedItem model. Table users { id int[pk] fullName string emailAddress string profileImageUrl string } Table posts { id int[pk] text string imageUrl string userId int } Ref: posts.userId > Table feedItems { id int userId int postId int postOwnerId int postCreatedAt timestamp } Ref: feedItems.userId > Ref: feedItems.postId > Ref: feedItems.postOwnerId >

Comments (1)
3 years ago
Hey Brian, I have a conceptual question regarding this video. Did you do this model for feeditems to show us how to do it efficiently using waterline? Or because it makes more sense visually to see it this way? My background is in python/django and SQL and I thought you were doing it for that reason, but watching it a second time I had an "aha!" moment and think I am finally pulling all of this together. I always imagined instagram did a new query every time they refreshed the page and didn't save each item actually into a model called "feedItem". I guess my idea for why you were doing this was because its better visually for us to learn it this way. But I feel like my Aha moment led me to think this is just the pattern to follow when using mongoDB or any noSQL.... am I understanding this correctly? Essentially, what's the point in making those complex queries through a number of objects when they touch and store a lot of unneeded data on the way to do their job. We can link the associating objects Id to the actual object and avoid the complex query by simply adding a column that tells the query to perform optimally by giving it better to directions to that data instead of telling it to grab all the data on the way to that object? I feel like I have been taught to always choose complex queries before you add any redundant column of data to your model. But is it actually just okay to add that column? If so, I think this just made back ends so much simpler
Brian Voong
3 years ago