Here's a basic plan for implementing a like or follow button in Backbone:
- Users will be connected to Posts via a "likes" join table.
PostBackbone model will be given a "like" attribute in the JSON it's sent from the server. If the current user doesn't like the post, then this will be empty. Otherwise, it will point to the id of the row in the "likes" table that joins the post and the user.
- Use this data to create a function in your
PostBackbone model, which points to an instance of a
- When the user clicks the button to toggle the "like" status, you will either destroy this
Likeinstance (if the user already likes the post), or pass it the id of the post and save it (if the user doesn't already like the post).