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 query started with a WITH clause to insert the new record:
WITH inserted_feed_follow AS (
INSERT INTO feed_follows ...
RETURNING *
)
Now that I have the new record in the inserted_feed_follow CTE, I can write a SELECT query to INNER JOIN it to the additional info I want:
SELECT
inserted_feed_follow.*,
feeds.name AS feed_name,
users.name AS user_name
FROM inserted_feed_follow
INNER JOIN ...
INNER JOIN ...