Move use of "load_namespaces" for DBIC from BasicCRUD to MoreCatalystBasics
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / MoreCatalystBasics.pod
index 8c1734e..e125cd7 100644 (file)
@@ -1,11 +1,11 @@
 =head1 NAME
 
-Catalyst::Manual::Tutorial::MoreCatalystBasics - Catalyst Tutorial - Part 3: More Catalyst Application Development Basics
+Catalyst::Manual::Tutorial::MoreCatalystBasics - Catalyst Tutorial - Chapter 3: More Catalyst Application Development Basics
 
 
 =head1 OVERVIEW
 
-This is B<Part 3 of 10> for the Catalyst tutorial.
+This is B<Chapter 3 of 10> for the Catalyst tutorial.
 
 L<Tutorial Overview|Catalyst::Manual::Tutorial>
 
@@ -56,13 +56,13 @@ L<Appendices|Catalyst::Manual::Tutorial::Appendices>
 
 =head1 DESCRIPTION
 
-This part of the tutorial builds on the work done in Part 2 to explore
-some features that are more typical of "real world" web applications.
-From this part of the tutorial onward, we will be building a simple
-book database application.  Although the application will be too
-limited to be of use to anyone, it should provide a basic environment
-where we can explore a variety of features used in virtually all web
-applications.
+This chapter of the tutorial builds on the work done in Chapter 2 to 
+explore some features that are more typical of "real world" web 
+applications. From this chapter of the tutorial onward, we will be 
+building a simple book database application.  Although the application 
+will be too limited to be of use to anyone, it should provide a basic 
+environment where we can explore a variety of features used in 
+virtually all web applications.
 
 You can checkout the source code for this example from the catalyst
 subversion repository as per the instructions in
@@ -74,8 +74,8 @@ L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>.
 The remainder of the tutorial will build an application called C<MyApp>.
 First use the Catalyst C<catalyst.pl> script to initialize the framework
 for the C<MyApp> application (make sure you aren't still inside the
-directory of the C<Hello> application from the previous part of the
-tutorial):
+directory of the C<Hello> application from the previous chapter of the
+tutorial or in a directory that already has a "MyApp" subdirectory):
 
     $ catalyst.pl MyApp
     created "MyApp"
@@ -86,7 +86,7 @@ tutorial):
     created "MyApp/script/myapp_create.pl"
     $ cd MyApp
 
-This creates a similar skeletal structure to what we saw in Part 2 of
+This creates a similar skeletal structure to what we saw in Chapter 2 of
 the tutorial, except with C<MyApp> and C<myapp> substituted for
 C<Hello> and C<hello>.
 
@@ -138,22 +138,23 @@ L<Config::General|Config::General> file (versus having the values
 hard-coded inside your Perl modules).  Config::General uses syntax
 very similar to Apache configuration files.  We will see how to use
 this feature of Catalyst during the authentication and authorization
-sections (Part 5 and Part 6).
-
-B<IMPORTANT NOTE:> If you are using a version of
-L<Catalyst::Devel|Catalyst::Devel> prior to version 1.06, you need to
-be aware that Catalyst changed from a default format of YAML to the
-more straightforward C<Config::General> format.  This tutorial use the
-newer C<myapp.conf> configuration file for C<Config::General> instead
-of C<myapp.yml> for YAML. However, Catalyst has long supported both
-formats and Catalyst will automatically use either C<myapp.conf> or
-C<myapp.yml> (or any other format supported by
-L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader> and
-L<Config::Any|Config::Any>).  If you are using a versions of
-Catalyst::Devel prior to 1.06, you can convert to the newer format by
-simply creating the C<myapp.conf> file manually and deleting
-C<myapp.yml>.  The default contents of C<myapp.conf> should only
-consist of one line: C<name MyApp>.
+sections (Chapter 5 and Chapter 6).
+
+B<IMPORTANT NOTE:> If you are using a version of 
+L<Catalyst::Devel|Catalyst::Devel> prior to version 1.06, be aware 
+that Catalyst changed the default format from YAML to the more 
+straightforward C<Config::General> style.  This tutorial uses the 
+newer C<myapp.conf> file for C<Config::General>. However, Catalyst 
+supports both formats and will automatically use either C<myapp.conf> 
+or C<myapp.yml> (or any other format supported by 
+L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader> and 
+L<Config::Any|Config::Any>).  If you are using a version of 
+Catalyst::Devel prior to 1.06, you can convert to the newer format by 
+simply creating the C<myapp.conf> file manually and deleting 
+C<myapp.yml>.  The default contents of the C<myapp.conf> you create 
+should only consist of one line: 
+
+    name MyApp
 
 B<TIP>: This script can be useful for converting between configuration
 formats:
@@ -161,10 +162,6 @@ formats:
     perl -Ilib -e 'use MyApp; use Config::General;
         Config::General->new->save_file("myapp.conf", MyApp->config);'
 
-B<NOTE:> The default C<myapp.conf> should look like:
-
-    name   MyApp
-
 =item *
 
 L<Catalyst::Plugin::Static::Simple|Catalyst::Plugin::Static::Simple>
@@ -176,31 +173,27 @@ as images and CSS files under the development server.
 
 For our application, we want to add one new plugin into the mix.  To 
 do this, edit C<lib/MyApp.pm> (this file is generally referred to as 
-your I<application class>) and delete the line with:
+your I<application class>) and delete the lines with:
 
-    __PACKAGE__->setup(qw/-Debug ConfigLoader Static::Simple/);
+    use Catalyst qw/-Debug
+                    ConfigLoader
+                    Static::Simple/;
 
 Then replace it with:
 
-    __PACKAGE__->setup(qw/
-            -Debug
-            ConfigLoader
-            Static::Simple
-    
-            StackTrace
-        /);
+    # Load plugins
+    use Catalyst qw/-Debug
+                ConfigLoader
+                Static::Simple
+                
+                StackTrace
+                /;
 
 B<Note:> Recent versions of C<Catalyst::Devel> have used a variety of 
-techniques to load these plugins/flags.  If you are following along in 
-Ubuntu 8.10, you should have C<Catalyst::Devel> v1.07 and see the 
-default code shown above.  If you are using v1.08, you should see the 
-following by default:
+techniques to load these plugins/flags.  For example, you might see
+the following:
 
-    use Catalyst qw/-Debug
-                ConfigLoader
-                Static::Simple/;
-    ...
-    __PACKAGE__->setup();
+    __PACKAGE__->setup(qw/-Debug ConfigLoader Static::Simple/);
 
 Don't let these variations confuse you -- they all accomplish the same 
 result.
@@ -254,7 +247,7 @@ actions:
     created "/home/me/MyApp/script/../lib/MyApp/Controller/Books.pm"
     created "/home/me/MyApp/script/../t/controller_Books.t"
 
-Then edit C<lib/MyApp/Controller/Books.pm> (as discussed in Part 2 of
+Then edit C<lib/MyApp/Controller/Books.pm> (as discussed in Chapter 2 of
 the Tutorial, Catalyst has a separate directory under C<lib/MyApp> for
 each of the three parts of MVC: C<Model>, C<View>, and C<Controller>)
 and add the following method to the controller:
@@ -381,7 +374,7 @@ types not discussed here (C<Regex> and C<LocalRegex>).
 
 =head1 CATALYST VIEWS
 
-As mentioned in Part 2 of the tutorial, views are where you render 
+As mentioned in Chapter 2 of the tutorial, views are where you render 
 output, typically for display in the user's web browser (but also 
 possibly using other display output-generation systems).  The code in 
 C<lib/MyApp/View> selects the I<type> of view to use, with the actual 
@@ -414,7 +407,7 @@ L<Catalyst::Helper::View::TTSite|Catalyst::Helper::View::TTSite>
 Both helpers are similar. C<TT> creates the C<lib/MyApp/View/TT.pm>
 file and leaves the creation of any hierarchical template organization
 entirely up to you. (It also creates a C<t/view_TT.t> file for testing;
-test cases will be discussed in Part 8.) C<TTSite>, on the other hand, 
+test cases will be discussed in Chapter 8.) C<TTSite>, on the other hand, 
 creates a modular and hierarchical view layout with
 separate Template Toolkit (TT) files for common header and footer
 information, configuration values, a CSS stylesheet, and more.
@@ -469,6 +462,12 @@ C<root> to C<root/src>.  These changes from the default are done mostly
 to facilitate the application we're developing in this tutorial; as with
 most things Perl, there's more than one way to do it...
 
+B<Note:> We will use C<root/src> as the base directory for our 
+template files, which a full naming convention of 
+C<root/src/_controller_name_/_action_name_.tt2>.  Another popular option is to
+use C<root/> as the base (with a full filename pattern of 
+C<root/_controller_name_/_action_name_.tt2>).
+
 
 =head2 Create a TT Template Page
 
@@ -606,7 +605,7 @@ can use the SQLite command line environment to do a quick dump of the
 database contents:
 
     $ sqlite3 myapp.db
-    SQLite version 3.4.2
+    SQLite version 3.5.9
     Enter ".help" for instructions
     sqlite> select * from books;
     1|CCSP SNRS Exam Certification Guide|5
@@ -635,6 +634,7 @@ your OS command prompt.
 For using other databases, such as PostgreSQL or MySQL, see 
 L<Appendix 2|Catalyst::Manual::Tutorial::Appendices>.
 
+
 =head1 DATABASE ACCESS WITH C<DBIx::Class>
 
 Catalyst can be used with virtually any form of persistent datastore 
@@ -655,7 +655,8 @@ Use the C<create=dynamic> model helper option to build a model that
 dynamically reads your database structure every time the application
 starts:
 
-    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=dynamic dbi:SQLite:myapp.db
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=dynamic dbi:SQLite:myapp.db
      exists "/home/me/MyApp/script/../lib/MyApp/Model"
      exists "/home/me/MyApp/script/../t"
      exists "/home/me/MyApp/script/../lib/MyApp"
@@ -664,19 +665,37 @@ starts:
     created "/home/me/MyApp/script/../t/model_DB.t"
 
 
+The C<script/myapp_create.pl> command breaks down like this:
+
+=over 4
+
+=item *
+
 C<DB> is the name of the model class to be created by the helper in 
-C<lib/MyApp/Model>.  C<DBIC::Schema> is the type of the model to 
-create. C<MyApp::Schema> is the name of the DBIC schema file written 
-to C<lib/MyApp/Schema.pm>.  Because we specified C<create=dynamic> to 
-the helper, it use 
+C<lib/MyApp/Model>.
+
+=item *
+
+C<DBIC::Schema> is the type of the model to create.
+
+=item *
+
+C<MyApp::Schema> is the name of the DBIC schema file written to
+C<lib/MyApp/Schema.pm>.
+
+=item *
+
+Because we specified C<create=dynamic> to the helper, it use 
 L<DBIx::Class::Schema::Loader|DBIx::Class::Schema::Loader> to 
 dynamically load the schema information from the database every time 
-the application starts. DBIC uses the schema to load other classes 
-that represent the tables in your database (DBIC refers to these 
-"table objects" as "result sources," see 
-L<DBIx::Class::ResultSource|DBIx::Class::ResultSource>). And finally, 
-C<dbi:SQLite:myapp.db> is the standard DBI connect string for use with 
-SQLite.
+the application starts.
+
+=item *
+
+And finally, C<dbi:SQLite:myapp.db> is the standard DBI connect string 
+for use with SQLite.
+
+=back
 
 B<NOTE:> Although the C<create=dynamic> option to the DBIC helper
 makes for a nifty demonstration, is only really suitable for very
@@ -686,9 +705,10 @@ use the C<create=static> option that we switch to below.
 
 =head1 ENABLE THE MODEL IN THE CONTROLLER
 
-Open C<lib/MyApp/Controller/Books.pm> and un-comment the model code we
-left disabled earlier (un-comment the line containing
-C<[$c-E<gt>model('DB::Books')-E<gt>all]> and delete the next 2 lines):
+Open C<lib/MyApp/Controller/Books.pm> and un-comment the model code we 
+left disabled earlier so that your version matches the following (un-
+comment the line containing C<[$c-E<gt>model('DB::Books')-E<gt>all]> 
+and delete the next 2 lines):
 
     =head2 list
     
@@ -712,8 +732,8 @@ C<[$c-E<gt>model('DB::Books')-E<gt>all]> and delete the next 2 lines):
         $c->stash->{template} = 'books/list.tt2';
     }
 
-B<TIP>: You may see the C<$c-E<gt>model('DB::Book')> un-commented 
-above written as C<$c-E<gt>model('DB')-E<gt>resultset('Book')>.  The 
+B<TIP>: You may see the C<$c-E<gt>model('DB::Books')> un-commented 
+above written as C<$c-E<gt>model('DB')-E<gt>resultset('Books')>.  The 
 two are equivalent.  Either way, C<$c-E<gt>model> returns a 
 L<DBIx::Class::ResultSet|DBIx::Class::ResultSet> which handles queries 
 against the database and iterating over the set of results that are 
@@ -736,9 +756,10 @@ and L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema>.
 
 =head2 Test Run The Application
 
-First, let's enable an environment variable option that causes
-DBIx::Class to dump the SQL statements it's using to access the database
-(this option can provide extremely helpful troubleshooting information):
+First, let's enable an environment variable that causes DBIx::Class to 
+dump the SQL statements used to access the database.  This is a 
+helpful trick when you are trying to debug your database-oriented 
+code:
 
     $ export DBIC_TRACE=1
 
@@ -755,7 +776,7 @@ log).
 Then launch the Catalyst development server.  The log output should
 display something like:
 
-    $script/myapp_server.pl
+    $ script/myapp_server.pl
     [debug] Debug messages enabled
     [debug] Statistics enabled
     [debug] Loaded plugins:
@@ -803,8 +824,8 @@ display something like:
     | /books/list                         | /books/list                          |
     '-------------------------------------+--------------------------------------'
     
-    [info] MyApp powered by Catalyst 5.7014
-    You can connect to your server at http://localhost:3000
+    [info] MyApp powered by Catalyst 5.71000
+    You can connect to your server at http://debian:3000
 
 B<NOTE:> Be sure you run the C<script/myapp_server.pl> command from
 the 'base' directory of your application, not inside the C<script>
@@ -854,7 +875,7 @@ more fully.
 
 =head1 CREATE A WRAPPER FOR THE VIEW
 
-When using TT, you can (and should!) create a wrapper that will
+When using TT, you can (and should) create a wrapper that will
 literally wrap content around each of your templates.  This is
 certainly useful as you have one main source for changing things that
 will appear across your entire site/application instead of having to
@@ -912,7 +933,6 @@ For the tutorial, open C<root/src/wrapper.tt2> and input the following:
         <ul>
             <li><a href="[% c.uri_for('/books/list') %]">Home</a></li>
             <li><a href="[% c.uri_for('/') %]" title="Catalyst Welcome Page">Welcome</a></li>
-            <li><a href="mailto:nobody@nowhere.com" title="Contact Us">Contact Us</a></li>
         </ul>
     </div><!-- end menu -->
     
@@ -951,7 +971,7 @@ B<Notes:>
 The Catalyst stash only lasts for a single HTTP request.  If
 you need to retain information across requests you can use
 L<Catalyst::Plugin::Session|Catalyst::Plugin::Session> (we will use
-Catalyst sessions in the Authentication part of the tutorial).
+Catalyst sessions in the Authentication chapter of the tutorial).
 
 =item *
 
@@ -1028,6 +1048,23 @@ template -- the wrapper will provide the overall feel of the page.
 
 =head1 A STATIC DATABASE MODEL WITH C<DBIx::Class>
 
+First, let's be sure we have a recent versino of the DBIC helper,
+L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema>, by
+running this command:
+
+    $ perl -MCatalyst::Model::DBIC::Schema -e \
+        'print "$Catalyst::Model::DBIC::Schema::VERSION\n"'
+    0.23
+
+If you don't have version 0.23 or higher, please run this command
+to install it directly from CPAN:
+
+    $ sudo cpan Catalyst::Model::DBIC::Schema
+
+And re-run the version print command to verify that you are now at 
+0.23 or higher.
+
+
 =head2 Create Static DBIC Schema Files
 
 Unlike the previous DBIC section where we had C<create=dynamic>
@@ -1045,12 +1082,13 @@ First, lets remove the schema file created earlier:
 
 Now regenerate the schema using the C<create=static> option:
 
-    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:SQLite:myapp.db
-     exists "/home/kclark/dev/MyApp/script/../lib/MyApp/Model"
-     exists "/home/kclark/dev/MyApp/script/../t"
-    Dumping manual schema for MyApp::Schema to directory /home/kclark/dev/MyApp/script/../lib ...
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=static components=TimeStamp dbi:SQLite:myapp.db
+     exists "/home/me/MyApp/script/../lib/MyApp/Model"
+     exists "/home/me/MyApp/script/../t"
+    Dumping manual schema for MyApp::Schema to directory /home/me/MyApp/script/../lib ...
     Schema dump completed.
-     exists "/home/kclark/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
+     exists "/home/me/MyApp/script/../lib/MyApp/Model/DB.pm"
 
 We could have also deleted C<lib/MyApp/Model/DB.pm>, but it would
 have regenerated the same file (note the C<exists> in the output above).
@@ -1064,39 +1102,77 @@ L<DBIx::Class::Schema::Loader|DBIx::Class::Schema::Loader> as its base
 class (L<DBIx::Class::Schema::Loader|DBIx::Class::Schema::Loader> is 
 only being used by the helper to load the schema once and then create 
 the static files for us) and C<Schema.pm> only contains a call to the 
-C<load_classes> method.  You will also find that C<lib/MyApp> 
-contains a C<Schema> subdirectory, with one file inside this directory 
-for each of the tables in our simple database (C<Authors.pm>, 
-C<BookAuthors.pm>, and C<Books.pm>).  These three files were created 
-based on the information found by 
-L<DBIx::Class::Schema::Loader|DBIx::Class::Schema::Loader> as the 
-helper ran.
-
-The idea with all of the files created under C<lib/MyApp/Schema> by 
-the C<create=static> option is to only edit the files below the C<# DO 
-NOT MODIFY THIS OR ANYTHING ABOVE!> warning.  If you place all of your 
-changes below that point in the file, you can regenerate the 
-automatically created information at the top of each file should your 
-database structure get updated.
-
-Also note the "flow" of the model information across the various files
-and directories.  Catalyst will initially load the model from
-C<lib/MyApp/Model/DB.pm>.  This file contains a reference to
-C<lib/MyApp/Schema.pm>, so that file is loaded next.  Finally,
-the call to C<load_classes> in C<Schema.pm> will load each of the
-table-specific "results source" files from the C<lib/MyApp/Schema>
-subdirectory.  These three table-specific DBIC schema files will then be
-used to create three table-specific Catalyst models every time the
-application starts (you can see these three model files listed in
-the debug output generated when you launch the application).
-
-
-=head2 Updating the Generated DBIC Schema Files
-
-Let's manually add some relationship information to the auto-generated
-schema files.  First edit C<lib/MyApp/Schema/Books.pm> and
-add the following text below the C<# You can replace this text...>
-comment:
+C<load_namespaces> method.  You will also find that C<lib/MyApp> 
+contains a C<Schema> subdirectory, which then has a subdirectory 
+called "Result".  This "Result" subdirectory then has files named 
+according to each of the tables in our simple database (C<Authors.pm>, 
+C<BookAuthors.pm>, and C<Books.pm>).  These three files are called 
+"Result Classes" in DBIC nomenclature. Although the Result Class files 
+are named after tables in our database, the classes correspond to the 
+I<row-level data> that is returned by DBIC (more on this later, 
+especially in 
+L<Catalyst::Manual::Tutorial::BasicCRUD/EXPLORING THE POWER OF DBIC>.
+
+The idea with the Result Source files created under 
+C<lib/MyApp/Schema/Result> by the C<create=static> option is to only 
+edit the files below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> 
+warning. If you place all of your changes below that point in the 
+file, you can regenerate the automatically created information at the 
+top of each file should your database structure get updated.
+
+Also note the "flow" of the model information across the various files 
+and directories.  Catalyst will initially load the model from 
+C<lib/MyApp/Model/DB.pm>.  This file contains a reference to 
+C<lib/MyApp/Schema.pm>, so that file is loaded next.  Finally, the 
+call to C<load_namespaces> in C<Schema.pm> will load each of the 
+"Result Class" files from the C<lib/MyApp/Schema/Result> subdirectory. 
+The final outcome is that Catalyst will dynamically create three 
+table-specific Catalyst models every time the application starts (you 
+can see these three model files listed in the debug output generated 
+when you launch the application).
+
+B<NOTE:> Older versions of 
+L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> use the 
+deprecated DBIC C<load_classes> technique instead of the newer 
+C<load_namspaces>.  For new applications, please try to use 
+C<load_namespaces> since it more easily supports a very useful DBIC 
+technique called "ResultSet Classes."  If you need to convert an 
+existing application from "load_classes" to "load_namespaces," you can 
+use this process to automate the migration (but first make sure you 
+have v0.23 C<Catalyst::Model::DBIC::Schema> as discussed above):
+
+    $ # First delete the existing schema file to disable "compatibility" mode
+    $ rm lib/MyApp/Schema.pm
+    $
+    $ # Then re-run the helper to build the files for "load_namespaces"
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=static components=TimeStamp dbi:SQLite:myapp.db
+    $
+    $ # Now convert the existing files over
+    $ cd lib/MyApp/Schema
+    $ perl -MIO::All -e 'for (@ARGV) { my $s < io($_); $s =~ s/.*\n\# You can replace.*?\n//s;
+          $s =~ s/'MyApp::Schema::/'MyApp::Schema::Result::/g; my $d < io("Result/$_");
+          $d =~ s/1;\n?//; "$d$s" > io("Result/$_"); }' *.pm
+    $ cd ../../..
+    $
+    $ # And finally delete the old files
+    $ rm lib/MyApp/Schema/*.pm
+
+The "C<perl -MIO::ALL ...>" script will copy all the customized 
+relationship (and other) information below "C<# DO NOT MODIFY>" line 
+from the old files in C<lib/MyApp/Schema> to the new files in 
+C<lib/MyApp/Schema/Result> (we will be starting to add some 
+"customized relationship information in the section below).
+
+
+=head2 Updating the Generated DBIC Result Class Files
+
+Let's manually add some relationship information to the auto-generated 
+Result Class files. (Note: if you are using a database other than 
+SQLite, such as PostgreSQL, then the relationship could have been 
+automatically placed in the Result Class files.  If so, you can skip 
+this step.)  First edit C<lib/MyApp/Schema/Result/Books.pm> and add the 
+following text below the C<# You can replace this text...> comment:
 
     #
     # Set relationships:
@@ -1106,8 +1182,8 @@ comment:
     #   args:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
-    #     3) Column name in *foreign* table
-    __PACKAGE__->has_many(book_authors => 'MyApp::Schema::BookAuthors', 'book_id');
+    #     3) Column name in *foreign* table (aka, foreign key in peer table)
+    __PACKAGE__->has_many(book_authors => 'MyApp::Schema::Result::BookAuthors', 'book_id');
     
     # many_to_many():
     #   args:
@@ -1123,6 +1199,17 @@ file.  As with any Perl package, we need to end the last line with
 a statement that evaluates to C<true>.  This is customarily done with
 C<1;> on a line by itself.
 
+C<Important Note:> Although this tutorial uses plural names for both 
+the names of the SQL tables and therefore the Result Classes (after 
+all, C<Schema::Loader> automatically named the Result Classes from the 
+names of the SQL tables it found), DBIC users prefer singular names 
+for these items.  B<Please try to use singular table and DBIC 
+model/Result Class names in your applications.>  This tutorial will 
+migrate to singular names as soon as possible (patches welcomed). 
+B<Note that while singular is preferred for the DBIC model, plural is 
+perfectly acceptable for the names of the controller classes.>  After 
+all, the C<Books.pm> controller operates on multiple books.
+
 This code defines both a C<has_many> and a C<many_to_many> relationship.
 The C<many_to_many> relationship is optional, but it makes it easier to
 map a book to its collection of authors.  Without it, we would have to
@@ -1136,7 +1223,7 @@ C<$book-E<gt>authors-E<gt>first-E<gt>last_name>.
 Note that you cannot define a C<many_to_many> relationship without 
 also having the C<has_many> relationship in place.
 
-Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
+Then edit C<lib/MyApp/Schema/Result/Authors.pm> and add relationship
 information as follows (again, be careful to put in above the C<1;> but
 below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):
 
@@ -1148,8 +1235,8 @@ below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):
     #   args:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
-    #     3) Column name in *foreign* table
-    __PACKAGE__->has_many(book_author => 'MyApp::Schema::BookAuthors', 'author_id');
+    #     3) Column name in *foreign* table (aka, foreign key in peer table)
+    __PACKAGE__->has_many(book_author => 'MyApp::Schema::Result::BookAuthors', 'author_id');
     
     # many_to_many():
     #   args:
@@ -1160,7 +1247,7 @@ below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):
     __PACKAGE__->many_to_many(books => 'book_author', 'book');
 
 Finally, do the same for the "join table,"
-C<lib/MyApp/Schema/BookAuthors.pm>:
+C<lib/MyApp/Schema/Result/BookAuthors.pm>:
 
     #
     # Set relationships:
@@ -1171,14 +1258,14 @@ C<lib/MyApp/Schema/BookAuthors.pm>:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *this* table
-    __PACKAGE__->belongs_to(book => 'MyApp::Schema::Books', 'book_id');
+    __PACKAGE__->belongs_to(book => 'MyApp::Schema::Result::Books', 'book_id');
     
     # belongs_to():
     #   args:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *this* table
-    __PACKAGE__->belongs_to(author => 'MyApp::Schema::Authors', 'author_id');
+    __PACKAGE__->belongs_to(author => 'MyApp::Schema::Result::Authors', 'author_id');
 
 
 =head2 Run The Application
@@ -1191,11 +1278,12 @@ is an alternate way to specify the option just in case):
 
 Make sure that the application loads correctly and that you see the
 three dynamically created model class (one for each of the
-table-specific schema classes we created).
+Result Classes we created).
 
-Then hit the URL L<http://localhost:3000/books/list> and be sure that 
-the book list is displayed via the relationships established above. You 
-can leave the development server running for the next step if you wish.
+Then hit the URL L<http://localhost:3000/books/list> with your browser 
+and be sure that the book list is displayed via the relationships 
+established above. You can leave the development server running for 
+the next step if you wish.
 
 B<Note:> You will not see the authors yet because the view does not yet 
 use the new relations. Read on to the next section where we update the 
@@ -1204,13 +1292,15 @@ template to do that.
 
 =head1 UPDATING THE VIEW
 
-Let's add a new column to our book list page that takes advantage of
-the relationship information we manually added to our schema files
-in the previous section.  Edit C<root/src/books/list.tt2> add add the
-following code below the existing table cell that contains
-C<book.rating> (IOW, add a new table cell below the existing two
-C<td> cells):
+Let's add a new column to our book list page that takes advantage of 
+the relationship information we manually added to our schema files in 
+the previous section.  Edit C<root/src/books/list.tt2> add add the 
+following code below the existing table cell that contains 
+C<book.rating> (IOW, add a new table cell below the existing two 
+C<E<lt>tdE<gt>> tags but above the closing C<E<lt>/trE<gt>> and 
+C<E<lt>/tableE<gt>> tags):
 
+    ...
     <td>
       [% # First initialize a TT variable to hold a list.  Then use a TT FOREACH -%]
       [% # loop in 'side effect notation' to load just the last names of the     -%]
@@ -1227,6 +1317,7 @@ C<td> cells):
       [% # Use another TT vmethod to join & print the names & comma separators   -%]
       [% tt_authors.join(', ') | html %]
     </td>
+    ...
 
 Then hit "Reload" in your browser (note that you don't need to reload 
 the development server or use the C<-r> option when updating TT 
@@ -1239,14 +1330,19 @@ browser window.)
 If you are still running the development server with C<DBIC_TRACE>
 enabled, you should also now see five more C<SELECT> statements in the
 debug output (one for each book as the authors are being retrieved by
-DBIC).
+DBIC):
 
     SELECT me.id, me.title, me.rating FROM books me:
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '1'
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '2'
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '3'
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '4'
-    SELECT me.book_id, me.author_id FROM book_authors me WHERE ( me.book_id = ? ): '5'
+    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 = ? ): '1'
+    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 = ? ): '2'
+    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 = ? ): '3'
+    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 = ? ): '4'
+    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 = ? ): '5'
 
 Also note in C<root/src/books/list.tt2> that we are using "| html", a 
 type of TT filter, to escape characters such as E<lt> and E<gt> to &lt; 
@@ -1279,10 +1375,11 @@ and asked your browser to view the page source.
 
 =head1 OPTIONAL INFORMATION
 
-B<NOTE: The rest of this part of the tutorial is optional.  You can
-skip to Part 4, L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>,
+B<NOTE: The rest of this chapter of the tutorial is optional.  You can
+skip to Chapter 4, L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>,
 if you wish.>
 
+
 =head2 Using C<RenderView> for the Default View
 
 Once your controller logic has processed the request from a user, it
@@ -1374,8 +1471,8 @@ as before.
 
 B<NOTE:> Please note that if you use the default template technique,
 you will B<not> be able to use either the C<$c-E<gt>forward> or
-the C<$c-E<gt>detach> mechanisms (these are discussed in Part 2 and
-Part 9 of the Tutorial).
+the C<$c-E<gt>detach> mechanisms (these are discussed in Chapter 2 and
+Chapter 9 of the Tutorial).
 
 
 =head2 Return To A Manually-Specified Template