Exercise Wednesday

This multi-day project will be 2 days for full-time and 4 days for part-time.

Goal for 1st half of project: Begin the multi-day project detailed below by creating a detailed schema of your application's relationships. Then create CRUD functionality and RESTful routes in the app.rb file. Ensure total spec coverage, including both unit tests and integration tests.

Goal for 2nd half of project: Build the many-to-many relationship between two classes/tables in which either trains can have many cities and cities can have many trains OR books can have many patrons and patrons can have many books.

Warm Up

1st Day of Project

  • Why do we execute many-to-many relationships with a join table?
  • When might we use a join statement? Why?

2nd Day of Project

  • What are some ways we can modify a SQL select statement? Why would we want to use these modifications?
  • What is ACID? Why is it important that a SQL database be ACID-compliant?
  • Walk through what RESTful routing looks like with your partner. Use this project as a reference, if necessary.


Multi-Day Project

Over the next few days, we will build an application that implements a many-to-many relationship between two classes and their corresponding database tables. With your partner, determine whether you'd like to build a train system or library as described below.

  • Complete the first goal by completing CRUD functionality and RESTful routing for each class/table (either Train and City or Book and Patron).
  • Then, complete the second goal by implementing the many-to-many relationship.

Train System

Make a program to map a train system. It should allow train system operators to add, update and delete information. It should allow train riders to read information regarding when and where they can ride a train.

Trains will stop in a number of cities and each city may have a number of trains coming through it.

Here are some user stories for you to get started:

  • As a train system operator, I want to create, read, update, delete and list trains, so that I can track all of the trains in my system.
  • As a train system operator, I want to create, read, update, delete and list cities where my trains will stop, so that I can manage where all of the trains will go.
  • As a train rider, I want to view a train, so that I can see the cities where it stops.
  • As a train rider, I want to view a city, so that I can see which trains come to it.
  • As a train rider, I want to see a timetable that shows what time each train stops in each city.
  • As a train rider, I want to purchase a ticket in a particular city for a particular train so that I can get on and off in any city that train travels. (This can work like a MAX ticket where you are able to purchase the ticket independent of the destination).

There is a many-to-many relationship between cities and trains. You might consider naming the cities_trains join table stops to reflect the relationship between the two.

When you list out the trains for a specific city, you'll need to start by selecting all stops for that city, and then selecting all trains for those stops.

Library System

Make a program to catalog a library's books and let patrons check them out.

Here are some user stories for you:

  • As a librarian, I want to create, read, update, delete, and list books in the catalog, so that we can keep track of our inventory.
  • As a librarian, I want to search for a book by author or title, so that I can find a book easily when the book inventory at the library grows large.
  • As a patron, I want to check a book out, so that I can take it home with me.
  • As a patron, I want to see a history of all the books I checked out, so that I can look up the name of that awesome sci-fi novel I read three years ago. (Hint: make a checkouts table that is a join table between patrons and books.)
  • As a patron, I want to know when a book I checked out is due, so that I know when to return it.
  • As a librarian, I want to see a list of overdue books, so that I can call up the patron who checked them out and tell them to bring them back — OR ELSE!
  • As a librarian, I want to enter multiple authors for a book, so that I can include accurate information in my catalog. (Hint: make an authors table and a books table with a many-to-many relationship.)

When you want to list out the books for a specific patron, you'll need to start by selecting all of the checkouts for that patron, and then selecting all of the books for those checkouts.

Further Exploration

If you have completed all of the user stories for your program and integration testing, consider adding:

  • join statements instead of join tables.
  • Select fields to your forms
  • Date pickers
  • Navigation (navbar), headers and footers to your layout.erb file
  • Images
  • Additional styling using Bootstrap's grid system

Peer Code Review

  • Does the database use standard naming convention for both columns and tables?
  • Is the many-to-many relationship set up correctly?
  • Is CRUD functionality being executed in class methods and routes?
  • Do routes correctly follow RESTful convention?
  • Does the application work as expected?

Lesson 24 of 29
Last updated August 7, 2022