To Lecture Notes

IT 231 -- 10/30/12

 

Review Questions

  1. What does the collect method of the Array class do?
    Ans: It takes all the items returned by the code block and collects them together into a single array. For example:
  2. What is a one-to-many relationship?
    Ans: A correspondence between two database tables where a row in the primary table is matched with zero or more rows in the secondary table.
     
  3. What is a primary key? What is a foreign key? Ans: In a Rails table, the primary key is the id, which is the row number of the table. This row number uniquely identifies the table row. A foreign key is a field in a database table that contains the primary key of a different table.
     
  4. How do you set up a one-to-many relationship in Rails?
  5. Can you think of an example involving three models A, B, and C, where there is a one-to-many relationship between A and B and there is also a one-to-many relationship between models B and C?
    Ans: Let A = Airline, B = Flight, C = Passenger. An airline has many flights, and a flight has many passengers.
     
  6. Create a Rails scaffold project with two models Patient and Doctor. Use this seed file code to get the field names and to populate the database tables. Then add a new controller named DocInfo with a view display that
     
    1. shows a table with the Patient names and his or her doctor's name and phone number,
       
    2. shows an unordered list with the Doctor names with an unordered list of Patient name and age for each doctor.

 

Project 6