April 2017
Beginner to intermediate
360 pages
9h 35m
English
One approach is to simply store the list of users in a text column in some serialized form. JSON is a versatile serialization format for such scenarios, so we'll use that. First, we'll add the column to the user_status_updates table, recalling the technique from the Adding columns to tables section in Chapter 7, Expanding Your Data Model:
ALTER TABLE "user_status_updates" ADD "starred_by_users" text;
Simple enough. Now let's suppose that bob wants to star one of the status updates of alice. From the application's standpoint, this means appending bob to the list of users who have starred alice's update. First, we'll read the existing list:
SELECT "starred_by_users" FROM "user_status_updates" WHERE "username" = ...
Read now
Unlock full access