We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Follow

Feeds currently have a creator (the user_id on the feed record) but there's no way for other users to follow feeds created by other users. And because we're making feeds unique by URL, they can't even add a feed that another user has already added.

We need to introduce a many-to-many relationship between users and feeds. Many users can follow the same feed, and a user can follow many feeds.

We'll use a joining table called feed_follows to accomplish this. Creating a feed_follow record indicates that a user is now following a feed. Deleting it is the same as "unfollowing" a feed.

Assignment

Run and submit the CLI tests.

Tips

My createFeedFollow function started with inserting the new record:

const [newFeedFollow] = await db.insert(feedFollows)...

Now that I have the record in newFeedFollow I can write a SELECT query to INNER JOIN it to the additional info I want.

  1. Select fields from:
    • feedFollows: Include metadata like id, createdAt, and updatedAt.
    • feeds: Add related fields such as the feed name.
    • users: Add related fields such as the user name.
  2. Join the tables:
    • Use .innerJoin() to connect the feedFollows table to feeds and users:
    • Join feeds where feedFollows.feedId = feeds.id.
    • Join users where feedFollows.userId = users.id.