Merge from depluralization branch
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / BasicCRUD.pod
index f6e098a..463e8d5 100644 (file)
@@ -61,7 +61,7 @@ application created in Chapter 3 to add basic support for Create,
 Read, Update, and Delete (CRUD) of C<Book> objects.  Note that the 
 'list' function in Chapter 2 already implements the Read portion of 
 CRUD (although Read normally refers to reading a single object; you 
-could implement full read functionality using the techniques 
+could implement full Read functionality using the techniques 
 introduced below).  This section will focus on the Create and Delete 
 aspects of CRUD.  More advanced capabilities, including full Update 
 functionality, will be addressed in Chapter 9.
@@ -74,8 +74,8 @@ L<CatalystX::ListFramework::Builder|CatalystX::ListFramework::Builder>,
 L<CatalystX::CRUD|CatalystX::CRUD>, and 
 L<CatalystX::CRUD::YUI|CatalystX::CRUD::YUI>.
 
-You can checkout the source code for this example from the catalyst
-subversion repository as per the instructions in
+You can check out the source code for this example from the Catalyst
+Subversion repository as per the instructions in
 L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>.
 
 
@@ -105,28 +105,20 @@ Edit C<lib/MyApp/Controller/Books.pm> and enter the following method:
 
         # Call create() on the book model object. Pass the table
         # columns/field values we want to set as hash values
-        my $book = $c->model('DB::Books')->create({
+        my $book = $c->model('DB::Book')->create({
                 title  => $title,
                 rating => $rating
             });
 
         # Add a record to the join table for this book, mapping to
         # appropriate author
-        $book->add_to_book_authors({author_id => $author_id});
+        $book->add_to_book_author({author_id => $author_id});
         # Note: Above is a shortcut for this:
-        # $book->create_related('book_authors', {author_id => $author_id});
+        # $book->create_related('book_author', {author_id => $author_id});
 
         # Assign the Book object to the stash for display in the view
         $c->stash->{book} = $book;
 
-        # This is a hack to disable XSUB processing in Data::Dumper
-        # (it's used in the view).  This is a work-around for a bug in
-        # the interaction of some versions or Perl, Data::Dumper & DBIC.
-        # You won't need this if you aren't using Data::Dumper (or if
-        # you are running DBIC 0.06001 or greater), but adding it doesn't
-        # hurt anything either.
-        $Data::Dumper::Useperl = 1;
-
         # Set the TT template to use
         $c->stash->{template} = 'books/create_done.tt2';
     }
@@ -135,12 +127,12 @@ Notice that Catalyst takes "extra slash-separated information" from the
 URL and passes it as arguments in C<@_>.  The C<url_create> action then
 uses a simple call to the DBIC C<create> method to add the requested
 information to the database (with a separate call to
-C<add_to_book_authors> to update the join table).  As do virtually all
+C<add_to_book_author> to update the join table).  As do virtually all
 controller methods (at least the ones that directly handle user input),
 it then sets the template that should handle this request.
 
 
-=head2 Include a Template for the C<url_create> Action:
+=head2 Include a Template for the 'url_create' Action:
 
 Edit C<root/src/books/create_done.tt2> and then enter:
 
@@ -151,8 +143,9 @@ Edit C<root/src/books/create_done.tt2> and then enter:
 
     [% # Set the page title.  META can 'go back' and set values in templates -%]
     [% # that have been processed 'before' this template (here it's for      -%]
-    [% # root/lib/site/html and root/lib/site/header).  Note that META on    -%]
-    [% # simple strings (e.g., no variable interpolation).                   -%]
+    [% # root/lib/site/html and root/lib/site/header).  Note that META only  -%]
+    [% # works on simple/static strings (i.e. there is no variable           -%]
+    [% # interpolation).                                                     -%]
     [% META title = 'Book Created' %]
 
     [% # Output information about the record that was added.  First title.       -%]
@@ -160,8 +153,8 @@ Edit C<root/src/books/create_done.tt2> and then enter:
 
     [% # Output the last name of the first author.  This is complicated by an    -%]
     [% # issue in TT 2.15 where blessed hash objects are not handled right.      -%]
-    [% # First, fetch 'book.authors' from the DB once.                           -%]
-    [% authors = book.authors %]
+    [% # First, fetch 'book.author' from the DB once.                           -%]
+    [% authors = book.author %]
     [% # Now use IF statements to test if 'authors.first' is "working". If so,   -%]
     [% # we use it.  Otherwise we use a hack that seems to keep TT 2.15 happy.   -%]
     by '[% authors.first.last_name IF authors.first;
@@ -188,7 +181,7 @@ variables.  Other than that, the rest of the code should be familiar
 from the examples in Chapter 3.
 
 
-=head2 Try the C<url_create> Feature
+=head2 Try the 'url_create' Feature
 
 If the application is still running from before, use C<Ctrl-C> to kill
 it. Then restart the server:
@@ -215,11 +208,8 @@ object as it was returned by DBIC.  You should also see the following
 DBIC debug messages displayed in the development server log messages
 if you have DBIC_TRACE set:
 
-    INSERT INTO books (rating, title) VALUES (?, ?): `5', `TCPIP_Illustrated_Vol-2'
-    INSERT INTO book_authors (author_id, book_id) VALUES (?, ?): `4', `6'
-    SELECT author.id, author.first_name, author.last_name
-        FROM book_authors me  JOIN authors author
-        ON ( author.id = me.author_id ) WHERE ( me.book_id = ? ): '6'
+    INSERT INTO book (rating, title) VALUES (?, ?): `5', `TCPIP_Illustrated_Vol-2'
+    INSERT INTO book_author (author_id, book_id) VALUES (?, ?): `4', `6'
 
 The C<INSERT> statements are obviously adding the book and linking it to
 the existing record for Richard Stevens.  The C<SELECT> statement results
@@ -227,7 +217,12 @@ from DBIC automatically fetching the book for the C<Dumper.dump(book)>.
 
 If you then click the "Return to list" link, you should find that
 there are now six books shown (if necessary, Shift+Reload or
-Ctrl+Reload your browser at the C</books/list> page).
+Ctrl+Reload your browser at the C</books/list> page).  You should now see
+the following six DBIC debug messages displayed for N=1-6:
+
+    SELECT author.id, author.first_name, author.last_name \
+        FROM book_author me  JOIN author author \
+        ON ( author.id = me.author_id ) WHERE ( me.book_id = ? ): 'N'
 
 
 =head1 CONVERT TO A CHAINED ACTION
@@ -242,11 +237,11 @@ entered above to match the following:
     sub url_create :Chained('/') :PathPart('books/url_create') :Args(3) {
 
 This converts the method to take advantage of the Chained
-action/dispatch type. Chaining let's you have a single URL
+action/dispatch type. Chaining lets you have a single URL
 automatically dispatch to several controller methods, each of which
 can have precise control over the number of arguments that it will
 receive.  A chain can essentially be thought of having three parts --
-a beginning, a middle and an end.  The bullets below summarize the key
+a beginning, a middle, and an end.  The bullets below summarize the key
 points behind each of these parts of a chain:
 
 
@@ -318,11 +313,10 @@ Specify the path to match with C<PathPart()>
 
 =back
 
-In our C<url_create> method above, we have combined all 3 parts into a
-single method: C<:Chained('/')> to start the chain,
-C<:PathPart('books/url_create')> to specify the base URL to match,
-along with C<:Args(3)> to capture exactly 3 arguments and also end the
-chain.
+In our C<url_create> method above, we have combined all three parts into
+a single method: C<:Chained('/')> to start the chain,
+C<:PathPart('books/url_create')> to specify the base URL to match, and
+C<:Args(3)> to capture exactly three arguments and to end the chain.
 
 As we will see shortly, a chain can consist of as many "links" as you
 wish, with each part capturing some arguments and doing some work
@@ -332,7 +326,7 @@ with the base method and delete feature below.  But Chained dispatch
 is capable of far more.  For additional information, see
 L<Catalyst::Manual::Intro/Action types>,
 L<Catalyst::DispatchType::Chained|Catalyst::DispatchType::Chained>,
-and the 2006 advent calendar entry on the subject:
+and the 2006 Advent calendar entry on the subject:
 L<http://www.catalystframework.org/calendar/2006/10>.
 
 
@@ -377,7 +371,7 @@ the lines of the following:
 
 C<url_create> has disappeared form the "Loaded Path actions" section
 but it now shows up under the newly created "Loaded Chained actions"
-section.  And, the "/*/*/*" portion clearly shows our requirement for
+section.  And the "/*/*/*" portion clearly shows our requirement for
 three arguments.
 
 As with our non-chained version of C<url_create>, use your browser to
@@ -387,11 +381,11 @@ enter the following URL:
 
 You should see the same "Added book 'TCPIP_Illustrated_Vol-2' by
 'Stevens' with a rating of 5." along with a dump of the new book model
-object.  Click the "Return to list" link, you should find that there
-are now seven books shown (two copies of TCPIP_Illustrated_Vol-2).
+object.  Click the "Return to list" link, and you should find that there
+are now seven books shown (two copies of I<TCPIP_Illustrated_Vol-2>).
 
 
-=head2 Refactor to Use a "Base" Method to Start the Chains
+=head2 Refactor to Use a 'base' Method to Start the Chains
 
 Let's make a quick update to our initial Chained action to show a
 little more of the power of chaining.  First, open
@@ -408,7 +402,7 @@ method:
         my ($self, $c) = @_;
 
         # Store the ResultSet in stash so it's available for other methods
-        $c->stash->{resultset} = $c->model('DB::Books');
+        $c->stash->{resultset} = $c->model('DB::Book');
 
         # Print a message to the debug log
         $c->log->debug('*** INSIDE BASE METHOD ***');
@@ -417,7 +411,7 @@ method:
 Here we print a log message and store the DBIC ResultSet in
 C<$c-E<gt>stash-E<gt>{resultset}> so that it's automatically available
 for other actions that chain off C<base>.  If your controller always
-needs a book ID as it's first argument, you could have the base method
+needs a book ID as its first argument, you could have the base method
 capture that argument (with C<:CaptureArgs(1)>) and use it to pull the
 book object with C<-E<gt>find($id)> and leave it in the stash for
 later parts of your chains to then act upon. Because we have several
@@ -451,10 +445,10 @@ Once again, enter the following URL into your browser:
     http://localhost:3000/books/url_create/TCPIP_Illustrated_Vol-2/5/4
 
 The same "Added book 'TCPIP_Illustrated_Vol-2' by 'Stevens' with a
-rating of 5" message and dump of the new book object should appear.
+rating of 5." message and a dump of the new book object should appear.
 Also notice the extra debug message in the development server output
-from the C<base> method.  Click the "Return to list" link, you should
-find that there are now eight books shown.
+from the C<base> method.  Click the "Return to list" link, and you
+should find that there are now eight books shown.
 
 
 =head1 MANUALLY BUILDING A CREATE FORM
@@ -482,7 +476,7 @@ Edit C<lib/MyApp/Controller/Books.pm> and add the following method:
         $c->stash->{template} = 'books/form_create.tt2';
     }
 
-This action simply invokes a view containing a book creation form.
+This action simply invokes a view containing a form to create a book.
 
 
 =head2 Add a Template for the Form
@@ -524,12 +518,12 @@ save the form information to the database:
         my $author_id = $c->request->params->{author_id} || '1';
 
         # Create the book
-        my $book = $c->model('DB::Books')->create({
+        my $book = $c->model('DB::Book')->create({
                 title   => $title,
                 rating  => $rating,
             });
         # Handle relationship with author
-        $book->add_to_book_authors({author_id => $author_id});
+        $book->add_to_book_author({author_id => $author_id});
 
         # Store new model object in stash
         $c->stash->{book} = $book;
@@ -578,7 +572,7 @@ Chapter 9.
 
 =head1 A SIMPLE DELETE FEATURE
 
-Turning our attention to the delete portion of CRUD, this section
+Turning our attention to the Delete portion of CRUD, this section
 illustrates some basic techniques that can be used to remove information
 from the database.
 
@@ -587,14 +581,14 @@ from the database.
 
 Edit C<root/src/books/list.tt2> and update it to match the following (two
 sections have changed: 1) the additional '<th>Links</th>' table header,
-and 2) the four lines for the Delete link near the bottom).
+and 2) the four lines for the Delete link near the bottom):
 
     [% # This is a TT comment.  The '-' at the end "chomps" the newline.  You won't -%]
     [% # see this "chomping" in your browser because HTML ignores blank lines, but  -%]
     [% # it WILL eliminate a blank line if you view the HTML source.  It's purely   -%]
     [%- # optional, but both the beginning and the ending TT tags support chomping. -%]
 
-    [% # Provide a title to root/lib/site/header -%]
+    [% # Provide a title -%]
     [% META title = 'Book List' -%]
 
     <table>
@@ -610,14 +604,15 @@ and 2) the four lines for the Delete link near the bottom).
           [% # authors into the list. Note that the 'push' TT vmethod doesn't return -%]
           [% # a value, so nothing will be printed here.  But, if you have something -%]
           [% # in TT that does return a value and you don't want it printed, you can -%]
-          [% # 1) assign it to a bogus value, or                                     -%]
-          [% # 2) use the CALL keyword to call it and discard the return value.      -%]
+          [% # 1) assign it to a bogus value, or # 2) use the CALL keyword to        -%]
+          [% # call it and discard the return value.                                 -%]
           [% tt_authors = [ ];
-             tt_authors.push(author.last_name) FOREACH author = book.authors %]
+             tt_authors.push(author.last_name) FOREACH author = book.author %]
           [% # Now use a TT 'virtual method' to display the author count in parens   -%]
-          ([% tt_authors.size %])
+          [% # Note the use of the TT filter "| html" to escape dangerous characters -%]
+          ([% tt_authors.size | html %])
           [% # Use another TT vmethod to join & print the names & comma separators   -%]
-          [% tt_authors.join(', ') %]
+          [% tt_authors.join(', ') | html %]
         </td>
         <td>
           [% # Add a link to delete a book %]
@@ -628,8 +623,9 @@ and 2) the four lines for the Delete link near the bottom).
     </table>
 
 The additional code is obviously designed to add a new column to the
-right side of the table with a C<Delete> "button" (for simplicity,
-links will be used instead of full HTML buttons).
+right side of the table with a C<Delete> "button" (for simplicity, links
+will be used instead of full HTML buttons; in practice, anything that
+modifies data should be handled with a form sending a PUT request).
 
 Also notice that we are using a more advanced form of C<uri_for> than
 we have seen before.  Here we use
@@ -639,7 +635,7 @@ while inserting the C<book.id> value into the appropriate place.  Now,
 if you ever change C<:PathPart('delete')> in your controller method to
 C<:PathPart('kill')>, then your links will automatically update
 without any changes to your .tt2 template file.  As long as the name
-of your method does not change ("delete" here), then your links will
+of your method does not change (here, "delete"), then your links will
 still be correct.  There are a few shortcuts and options when using
 C<action_for()>:
 
@@ -704,9 +700,9 @@ Now, any other method that chains off C<object> will automatically
 have the appropriate book waiting for it in
 C<$c-E<gt>stash-E<gt>{object}>.
 
-Also note that we are using different technique for setting
-C<$c-E<gt>stash>.  The advantage of this style is that it let's you
-set multiple stash variables at a time.  For example:
+Also note that we are using a different technique for setting
+C<$c-E<gt>stash>.  The advantage of this style is that it lets you set
+multiple stash variables at a time.  For example:
 
     $c->stash(object => $c->stash->{resultset}->find($id),
               another_thing => 1);
@@ -717,7 +713,7 @@ or as a hashref:
               another_thing => 1});
 
 Either format works, but the C<$c-E<gt>stash(name =E<gt> value);>
-style is growing in popularity -- you may which to use it all
+style is growing in popularity -- you may wish to use it all
 the time (even when you are only setting a single value).
 
 
@@ -736,7 +732,7 @@ following method:
         my ($self, $c) = @_;
 
         # Use the book object saved by 'object' and delete it along
-        # with related 'book_authors' entries
+        # with related 'book_author' entries
         $c->stash->{object}->delete;
 
         # Set a status message to be displayed at the top of the view
@@ -748,7 +744,7 @@ following method:
 
 This method first deletes the book object saved by the C<object> method.
 However, it also removes the corresponding entry from the
-C<book_authors> table with a cascading delete.
+C<book_author> table with a cascading delete.
 
 Then, rather than forwarding to a "delete done" page as we did with the
 earlier create example, it simply sets the C<status_msg> to display a
@@ -792,10 +788,10 @@ the "Delete" link next to the first "TCPIP_Illustrated_Vol-2".  A green
 along with a list of the eight remaining books.  You will also see the
 cascading delete operation via the DBIC_TRACE output:
 
-    SELECT me.id, me.title, me.rating FROM books me WHERE ( ( me.id = ? ) ): '6'
-    DELETE FROM books WHERE ( id = ? ): '6'
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '6'
-    DELETE FROM book_authors WHERE ( author_id = ? AND book_id = ? ): '4', '6'
+    SELECT me.id, me.title, me.rating FROM book me WHERE ( ( me.id = ? ) ): '6'
+    DELETE FROM book WHERE ( id = ? ): '6'
+    SELECT me.book_id, me.author_id FROM book_author me WHERE ( me.book_id = ? ): '6'
+    DELETE FROM book_author WHERE ( author_id = ? AND book_id = ? ): '4', '6'
 
 
 =head2 Fixing a Dangerous URL
@@ -832,7 +828,7 @@ C<sub delete> method to match:
         my ($self, $c) = @_;
 
         # Use the book object saved by 'object' and delete it along
-        # with related 'book_authors' entries
+        # with related 'book_author' entries
         $c->stash->{object}->delete;
 
         # Set a status message to be displayed at the top of the view
@@ -858,11 +854,11 @@ involves a second request), the C<status_msg> is cleared before it can
 be displayed.
 
 
-=head2 Using C<uri_for> to Pass Query Parameters
+=head2 Using 'uri_for' to Pass Query Parameters
 
 There are several ways to pass information across a redirect. One 
 option is to use the C<flash> technique that we will see in Chapter 5 
-of the tutorial; however, here we will pass the information via query 
+of this tutorial; however, here we will pass the information via query 
 parameters on the redirect itself.  Open 
 C<lib/MyApp/Controller/Books.pm> and update the existing C<sub delete> 
 method to match the following:
@@ -877,7 +873,7 @@ method to match the following:
         my ($self, $c) = @_;
 
         # Use the book object saved by 'object' and delete it along
-        # with related 'book_authors' entries
+        # with related 'book_author' entries
         $c->stash->{object}->delete;
 
         # Redirect the user back to the list page with status msg as an arg
@@ -922,7 +918,7 @@ C<flash> is a "slicker" mechanism in that it's all handled by the
 server and doesn't "pollute" your URLs, B<it is important to note that
 C<flash> can lead to situations where the wrong information shows up
 in the wrong browser window if the user has multiple windows or
-browser tabs open.>  For example, Window A causes something to be
+browser tabs open>.  For example, Window A causes something to be
 placed in the stash, but before that window performs a redirect,
 Window B makes a request to the server and gets the status information
 that should really go to Window A.  For this reason, you may wish
@@ -943,10 +939,10 @@ Let's add two columns to our existing C<books> table to track when
 each book was added and when each book is updated:
 
     $ sqlite3 myapp.db
-    sqlite> ALTER TABLE books ADD created INTEGER;
-    sqlite> ALTER TABLE books ADD updated INTEGER;
-    sqlite> UPDATE books SET created = DATETIME('NOW'), updated = DATETIME('NOW');
-    sqlite> SELECT * FROM books;
+    sqlite> ALTER TABLE book ADD created INTEGER;
+    sqlite> ALTER TABLE book ADD updated INTEGER;
+    sqlite> UPDATE book SET created = DATETIME('NOW'), updated = DATETIME('NOW');
+    sqlite> SELECT * FROM book;
     1|CCSP SNRS Exam Certification Guide|5|2009-03-08 16:26:35|2009-03-08 16:26:35
     2|TCP/IP Illustrated, Volume 1|5|2009-03-08 16:26:35|2009-03-08 16:26:35
     3|Internetworking with TCP/IP Vol.1|4|2009-03-08 16:26:35|2009-03-08 16:26:35
@@ -960,7 +956,7 @@ This will modify the C<books> table to include the two new fields
 and populate those fields with the current time.
 
 
-=head2 Update DBIC to Automatically Handle the Datetime Columns
+=head2 Update DBIx::Class to Automatically Handle the Datetime Columns
 
 Next, we should re-run the DBIC helper to update the Result Classes
 with the new fields:
@@ -974,12 +970,12 @@ with the new fields:
      exists "/root/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
 
 Notice that we modified our use of the helper slightly: we told
-it to include the L<DBIx::Class::Timestamp|DBIx::Class::Timestamp>
+it to include the L<DBIx::Class::TimeStamp|DBIx::Class::TimeStamp>
 in the C<load_components> line of the Result Classes.
 
-If you open C<lib/MyApp/Schema/Result/Books.pm> in your editor you
+If you open C<lib/MyApp/Schema/Result/Book.pm> in your editor you
 should see that the C<created> and C<updated> fields are now included
-in the call to add_columns(), but our relationship information below
+in the call to C<add_columns()>, but our relationship information below
 the "C<# DO NOT MODIFY...>" line was automatically preserved.
 
 While we have this file open, let's update it with some additional
@@ -998,10 +994,11 @@ B<above> the C<1;> on the last line):
         { data_type => 'datetime', set_on_create => 1, set_on_update => 1 },
     );
 
-This will override the definition for these fields that Schema::Loader
-placed at the top of the file.  The C<set_on_create> and
-C<set_on_update> options will cause DBIC to automatically update the
-timestamps in these columns whenever a row is created or modified.
+This will override the definition for these fields that Schema::Loader 
+placed at the top of the file.  The C<set_on_create> and 
+C<set_on_update> options will cause DBIx::Class to automatically 
+update the timestamps in these columns whenever a row is created or 
+modified.
 
 To test this out, restart the development server using the
 C<DBIC_TRACE=1> option:
@@ -1017,7 +1014,7 @@ if you now use the sqlite3 command-line tool to dump the C<books> table,
 you will see that the new book we added has an appropriate date and
 time entered for it (see the last line in the listing below):
 
-    sqlite3 myapp.db "select * from books"
+    sqlite3 myapp.db "select * from book"
     1|CCSP SNRS Exam Certification Guide|5|2009-03-08 16:26:35|2009-03-08 16:26:35
     2|TCP/IP Illustrated, Volume 1|5|2009-03-08 16:26:35|2009-03-08 16:26:35
     3|Internetworking with TCP/IP Vol.1|4|2009-03-08 16:26:35|2009-03-08 16:26:35
@@ -1029,9 +1026,9 @@ time entered for it (see the last line in the listing below):
 Notice in the debug log that the SQL DBIC generated has changed to
 incorporate the datetime logic:
 
-    INSERT INTO books (created, rating, title, updated) VALUES (?, ?, ?, ?):
+    INSERT INTO book (created, rating, title, updated) VALUES (?, ?, ?, ?):
     '2009-03-08 16:29:08', '5', 'TCPIP_Illustrated_Vol-2', '2009-03-08 16:29:08'
-    INSERT INTO book_authors (author_id, book_id) VALUES (?, ?): '4', '10'
+    INSERT INTO book_author (author_id, book_id) VALUES (?, ?): '4', '10'
 
 
 =head2 Create a ResultSet Class
@@ -1046,13 +1043,13 @@ controller code.
 
 To illustrate the concept with a fairly simple example, let's create a
 method that returns books added in the last 10 minutes.  Start by
-making a directory where DBIC will look for our ResultSet Class:
+making a directory where DBIx::Class will look for our ResultSet Class:
 
     mkdir lib/MyApp/Schema/ResultSet
 
-Then open C<lib/MyApp/Schema/ResultSet/Books.pm> and enter the following:
+Then open C<lib/MyApp/Schema/ResultSet/Book.pm> and enter the following:
 
-    package MyApp::Schema::ResultSet::Books;
+    package MyApp::Schema::ResultSet::Book;
 
     use strict;
     use warnings;
@@ -1078,13 +1075,13 @@ Then open C<lib/MyApp/Schema/ResultSet/Books.pm> and enter the following:
     1;
 
 Then we need to tell the Result Class to to treat this as a ResultSet
-Class.  Open C<lib/MyApp/Schema/Result/Books.pm> and add the following
+Class.  Open C<lib/MyApp/Schema/Result/Book.pm> and add the following
 above the "C<1;>" at the bottom of the file:
 
     #
     # Set ResultSet Class
     #
-    __PACKAGE__->resultset_class('MyApp::Schema::ResultSet::Books');
+    __PACKAGE__->resultset_class('MyApp::Schema::ResultSet::Book');
 
 Then add the following method to the C<lib/MyApp/Controller/Books.pm>:
 
@@ -1100,7 +1097,7 @@ Then add the following method to the C<lib/MyApp/Controller/Books.pm>:
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template, but only
         # retrieve books created within the last $min number of minutes
-        $c->stash->{books} = [$c->model('DB::Books')
+        $c->stash->{books} = [$c->model('DB::Book')
                                 ->created_after(DateTime->now->subtract(minutes => $mins))];
 
         # Set the TT template to use.  You will almost always want to do this
@@ -1122,18 +1119,20 @@ try a higher or lower value.
 
 =head2 Chaining ResultSets
 
-One of the most helpful and powerful features in DBIC is that it
-allows you to "chain together" a series of queries (note that this has
-nothing to do with the "Chained Dispatch" for Catalyst that we were
-discussing above).  Because each ResultSet returns another ResultSet,
-you can take an initial query and immediately feed that into a second
-query (and so on for as many queries you need).  And, because this
-technique carries over to the ResultSet Class feature we implemented
-in the previous section for our "canned search", we can combine the
-two capabilities.  For example, let's add an action to our C<Books>
-controller that lists books that are both recent I<and> have "TCP" in
-the title.  Open up C<lib/MyApp/Controller/Books.pm> and add the
-following method:
+One of the most helpful and powerful features in DBIx::Class is that 
+it allows you to "chain together" a series of queries (note that this 
+has nothing to do with the "Chained Dispatch" for Catalyst that we 
+were discussing above).  Because each ResultSet returns another 
+ResultSet, you can take an initial query and immediately feed that 
+into a second query (and so on for as many queries you need). Note 
+that no matter how many ResultSets you chain together, the database 
+itself will not be hit until you use a method that attempts to access 
+the data. And, because this technique carries over to the ResultSet 
+Class feature we implemented in the previous section for our "canned 
+search", we can combine the two capabilities.  For example, let's add 
+an action to our C<Books> controller that lists books that are both 
+recent I<and> have "TCP" in the title.  Open up 
+C<lib/MyApp/Controller/Books.pm> and add the following method:
 
     =head2 list_recent_tcp
 
@@ -1148,7 +1147,7 @@ following method:
         # stash where they can be accessed by the TT template, but only
         # retrieve books created within the last $min number of minutes
         # AND that have 'TCP' in the title
-        $c->stash->{books} = [$c->model('DB::Books')
+        $c->stash->{books} = [$c->model('DB::Book')
                                 ->created_after(DateTime->now->subtract(minutes => $mins))
                                 ->search({title => {'like', '%TCP%'}})
                              ];
@@ -1178,13 +1177,13 @@ how recently you added books to your database):
 Take a look at the DBIC_TRACE output in the development server log for
 the first URL and you should see something similar to the following:
 
-    SELECT me.id, me.title, me.rating, me.created, me.updated FROM books me
+    SELECT me.id, me.title, me.rating, me.created, me.updated FROM book me
     WHERE ( ( ( title LIKE ? ) AND ( created > ? ) ) ): '%TCP%', '2009-03-08 14:52:54'
 
 However, let's not pollute our controller code with this raw "TCP"
 query -- it would be cleaner to encapsulate that code in a method on
 our ResultSet Class.  To do this, open
-C<lib/MyApp/Schema/ResultSet/Books.pm> and add the following method:
+C<lib/MyApp/Schema/ResultSet/Book.pm> and add the following method:
 
     =head2 title_like
 
@@ -1219,7 +1218,7 @@ shown here -- the rest of the method should be the same):
         # stash where they can be accessed by the TT template, but only
         # retrieve books created within the last $min number of minutes
         # AND that have 'TCP' in the title
-        $c->stash->{books} = [$c->model('DB::Books')
+        $c->stash->{books} = [$c->model('DB::Book')
                                 ->created_after(DateTime->now->subtract(minutes => $mins))
                                 ->title_like('TCP')
                              ];
@@ -1238,16 +1237,16 @@ more flexible at the same time.
 
 =head2 Adding Methods to Result Classes
 
-In the previous two sections we saw a good example of how we could use
-DBIC ResultSet Classes to clean up our code for an entire query (for
-example, our "canned searches" that filtered the entire query).  We
-can do a similar improvement when working with individual rows as
-well.  Whereas the ResultSet construct is used in DBIC to correspond
-to an entire query, the Result Class construct is used to represent a
-row. Therefore, we can add row-specific "helper methods" to our Result
-Classes stored in C<lib/MyApp/Schema/Result/>. For example, open
-C<lib/MyApp/Schema/Result/Authors.pm> and add the following method
-(as always, it must be above the closing "C<1;>"):
+In the previous two sections we saw a good example of how we could use 
+DBIx::Class ResultSet Classes to clean up our code for an entire query 
+(for example, our "canned searches" that filtered the entire query). 
+We can do a similar improvement when working with individual rows as 
+well.  Whereas the ResultSet construct is used in DBIC to correspond 
+to an entire query, the Result Class construct is used to represent a 
+row. Therefore, we can add row-specific "helper methods" to our Result 
+Classes stored in C<lib/MyApp/Schema/Result/>. For example, open 
+C<lib/MyApp/Schema/Result/Author.pm> and add the following method (as 
+always, it must be above the closing "C<1;>"):
 
     #
     # Helper methods
@@ -1264,14 +1263,14 @@ and change the definition of C<tt_authors> from this:
 
     ...
       [% tt_authors = [ ];
-         tt_authors.push(author.last_name) FOREACH author = book.authors %]
+         tt_authors.push(author.last_name) FOREACH author = book.author %]
     ...
 
 to:
 
     ...
       [% tt_authors = [ ];
-         tt_authors.push(author.full_name) FOREACH author = book.authors %]
+         tt_authors.push(author.full_name) FOREACH author = book.author %]
     ...
 
 (Only C<author.last_name> was changed to C<author.full_name> -- the