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.
Run and submit the CLI tests.
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.
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..innerJoin()
to connect the feedFollows
table to feeds
and users
:feeds
where feedFollows.feedId = feeds.id
.users
where feedFollows.userId = users.id
.The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run a30bbb9f-fc70-4503-930e-0c0260b1fc89
Submit
bootdev run a30bbb9f-fc70-4503-930e-0c0260b1fc89 -s
To run and submit the tests for this lesson, you must have an active Boot.dev membership
Become a member to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.