Project Assignment 14

Ruby ActiveRecord and MySQL

You hear a knock at your office door. It could only mean one thing.

"Heeeyyyyy!! Great job on the Web-based PHP stuff you started for OmniTunes!" says your boss and then, strangely, stands there silent, grinning.

"What?" you blurt.

"Ok, ok, I have some bad news," he says. "We finally realized that all of our application developers were incompetent so we've given all of them some cool new programming tools to help them. See, you're the only person here that understands a thing about see-quell and databases. So the developers are going to use an ORN tool or something to work with your database,"

"I think you mean ORM. Anyway, that's great!"

"Ok, I'm glad you're all for it, because it means we need a new proof of concept from you. But this time we're going to use some woman named Ruby to help. I haven't met her yet but -- "

"Look, don't worry about a thing. I've already met her. We should have this demo ready in about a week," you tell your boss, while gesturing for the door.

He stares at you with a strange, superficial look of appreciation. "Thank you," he says, with a tear in his eye, "It means so much to me. Well, gotta run!"

All you can do is sigh. But at least you get to spend time programming with Ruby! What a gal!

Create an ActiveRecord proof of concept for the developers

This assignment intends to illustrate the convenience that powerful ORM tools give you when working with relational databases.

You will create just one source file that contains all of your ActiveRecord classes and your script, which must:

Start with this source file, which contains some hints at using ActiveRecord. Copy this file into your development environment. You can run it with the command ruby myfile.rb. The purpose of this assignment is to illustrate the comparative ease of an ORM, and not so much about Ruby. So if you get stuck, seek help immediately!

You will have to declare a class for each table involved in the above tasks. You'll also have to tell ActiveRecord the relationships between those classes. An example is provided in the source file.

Hints

By default, ActiveRecord assumes that each table has a PK called id and that table names are the pluralized, lower-case versions of the class names. So a Genre class needs a table called genres and a PK called id. You can override this (see the source file).

Use the ActiveRecord documentation for reference.

The provided source file is configured to write the SQL queries generated by ActiveRecord to a log file. Read it.

Seek help if you have problems with Ruby syntax or anything else!

Specific Tasks

Include the source file in your project documentation.

Read the log file created by ActiveRecord, and note the queries it generated for you.

To be completed by Wednesday, April 16