Update the "DBIC terminology" based on input from MST. Put in a note about "load_nam...
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / MoreCatalystBasics.pod
index 8c1734e..1c2086a 100644 (file)
@@ -140,20 +140,21 @@ 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>.
+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>
@@ -664,19 +661,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
@@ -712,8 +727,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 +751,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
 
@@ -1079,16 +1095,46 @@ 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).
+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 "result 
+class" files from the C<lib/MyApp/Schema> subdirectory.  The end 
+result 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:> The version of 
+L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> in 
+Ubuntu 8.10 uses the older DBIC C<load_classes> vs. the newer 
+C<load_namspaces> technique.  For new applications, please try to use 
+C<load_namespaces> since it more easily supports a very useful DBIC
+technique called "ResultSet Classes."  This tutorial expects to migrate to 
+C<load_namespaces> when the next release of Ubuntu comes out.
+
+If you wish to try C<load_namespaces> now, you can manually do the
+equivalent of the C<create=static> operation outside of the Catalyst
+helper:
+
+    perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib -e \
+        'make_schema_at("MyApp::Schema", { debug => 1, use_namespaces => 1, \
+        components => ["InflateColumn::DateTime"] },["dbi:SQLite:myapp.db", "", "" ])'
+
+And then use the helper to only create the Catalyst model class:
+
+    script/myapp_create.pl model DB DBIC::Schema MyApp::Schema dbi:SQLite:myapp.db
+
+B<However>, it is important to note that C<load_namespaces> will look 
+for your C<Books.pm>, <Authors.pm>, etc. files in 
+C<lib/MyApp/Schema/Result> (it adds the subdirection "Result" so that 
+there can also be a "ResultSet" directory next to it in the 
+hierarchy).  Therefore, if you switch to C<load_namespaces>, you will 
+need to modify the path to these "result class" files throughout the 
+rest of the tutorial.  Our recommendation for now would be to complete 
+the tutorial using C<load_classes> and the try converting to 
+C<load_namespaces> after you are done.
 
 
 =head2 Updating the Generated DBIC Schema Files
@@ -1106,7 +1152,7 @@ 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
+    #     3) Column name in *foreign* table (aka, foreign key in peer table)
     __PACKAGE__->has_many(book_authors => 'MyApp::Schema::BookAuthors', 'book_id');
     
     # many_to_many():
@@ -1148,7 +1194,7 @@ 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
+    #     3) Column name in *foreign* table (aka, foreign key in peer table)
     __PACKAGE__->has_many(book_author => 'MyApp::Schema::BookAuthors', 'author_id');
     
     # many_to_many():