Giter Site home page Giter Site logo

node-js-fakebook-g-416's Introduction

Making Our Blog Social (Lab)

Overview

In this lab, we will transform our blog server into a social platform.

Introduction

Blogs, as we know, are powerful platforms for communication, but in the last years what we've seen over and over again is the growth of a new social form on the internet: the social platform. We all use them: Facebook, Instagram, etc. There are a number of individual features that characterize these platforms, but arguably one of the most central is the ability to follow (and unfollow) users.

What we'll be doing in this lab, then, is building this core social feature into the blogging platform that we've been constructing. The feature is so common as to be cliche, but implementing this feature involves some interesting challenges, so this will be an interesting project.

Our specification

Wihtout further ado, here's the specification that we must meet:

  1. Users can follow other users.
  2. Users can unfollow other users.
  3. Users can have followers.
  4. When the user is logged in, and they load the home page (/), they will see a list of recent posts by users that they follow in descending order by date.

In addition, as usual, consult the tests in the /tests directory for additional specifications.

Some Considerations

As we begin work on this lab, it will pay to think a bit about the kind of database relationship that we'll need to establish in order to represent the relation of follower and followed. There are, as you may recall, three kinds of relational database relationships:

  1. One-to-one: where one record in table A relates directly to another record in table B. For example, in an Ecommerce site an orders table might have a one-to-one relationship between a shipping address and an addresses table.

  2. One-to-many: where one record in one table A relates to many records in table B. For example, a table of pet owners might have a one-to-many relationship with a table of pets.

  3. Many-to-many: where one record in table A relates to many records in table B, and a record in table B may also relate to many records in table A. For example, a table of books may relate to many records in an authors table (because you can have more than one author for a book), at the same time as one author may relate to many records in a books table (because authors frequently write multiple books). This kind of relation is usually achieved by creating an interim table, whose individual rows contain the primary keys from each table in the relation, like so:

    Many-to-many Table Diagram

So which one are we going to need for this project? Does one user have many followers? Yep. But also can one user follow many users? Yep also. So this is a many-to-many? Sounds like it. But something else is going on here: in both cases we are talking about a user. The relation is between the table and itself. This is a self-referencing many-to-many relationship.

Ah, so now we see the challenge here. Let's see if you can use Bookshelf to get this working. A word of warning here: we'll need to read the documentation for Bookshelf carefully here. In particular, we should read the documentation for many-to-many relationships in Bookshelf, and look closely at the explanations for the following methods: belongsToMany(), attach(), and detach(), and related().

Okay, good luck!

Resources

node-js-fakebook-g-416's People

Contributors

ezmiller avatar markdenardo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.