no need to set resultset_class with load_namespaces, and a couple other minor changes
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / 04_BasicCRUD.pod
index b747f66..cd3f0c4 100644 (file)
@@ -70,7 +70,7 @@ Although this chapter of the tutorial will show you how to build CRUD
 functionality yourself, another option is to use a "CRUD builder" type 
 of tool to automate the process.  You get less control, but it's quick 
 and easy.  For example, see 
-L<CatalystX::ListFramework::Builder|CatalystX::ListFramework::Builder>, 
+L<Catalyst::Plugin::AutoCRUD|Catalyst::Plugin::AutoCRUD>, 
 L<CatalystX::CRUD|CatalystX::CRUD>, and 
 L<CatalystX::CRUD::YUI|CatalystX::CRUD::YUI>.
 
@@ -183,10 +183,9 @@ outputs the "last name for the first author" above to match this:
 
 to get around an issue in TT v2.15 where blessed hash objects were not 
 handled correctly.  But, if you are still using v2.15, it's probably 
-time to upgrade  (v2.15 is exactly 3 years old on the day I'm typing 
-this).  If you are following along in Debian, then you should be on at 
-least v2.20.  You can test your version of Template Toolkit with the 
-following:
+time to upgrade  (v2.15 is 3.5+ years old).  If you are following 
+along in Debian, then you should be on at least v2.20.  You can test 
+your version of Template Toolkit with the following:
 
     perl -MTemplate -e 'print "$Template::VERSION\n"'
 
@@ -231,13 +230,10 @@ Ctrl+Reload your browser at the C</books/list> page).  You should now
 see the six DBIC debug messages similar to the following (where 
 N=1-6):
 
-    SELECT author.id, author.first_name, author.last_name \
-        FROM book_author me  JOIN author author \
+    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'
 
-(The '\' characters won't actually appear in the output -- we are 
-using them as "line continuation markers" here.)
-
 
 =head1 CONVERT TO A CHAINED ACTION
 
@@ -465,8 +461,7 @@ C</books> part of the URL.  However, the processing then continues to
 the C<url_create> method because this method "chained" off C<base> and 
 specified C<:PathPart('url_create')> (note that we could have omitted 
 the "PathPart" here because it matches the name of the method, but we 
-will include it to make the logic behind the tutorial as explicit as 
-possible).
+will include it to make the logic as explicit as possible).
 
 Once again, enter the following URL into your browser:
 
@@ -518,7 +513,7 @@ This action simply invokes a view containing a form to create a book.
 Open C<root/src/books/form_create.tt2> in your editor and enter:
 
     [% META title = 'Manual Form Book Create' -%]
-
+    
     <form method="post" action="[% c.uri_for('form_create_do') %]">
     <table>
       <tr><td>Title:</td><td><input type="text" name="title"></td></tr>
@@ -1002,7 +997,8 @@ Next, we should re-run the DBIC helper to update the Result Classes
 with the new fields:
 
     $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
-        create=static components=TimeStamp dbi:SQLite:myapp.db
+        create=static components=TimeStamp dbi:SQLite:myapp.db \
+        on_connect_do="PRAGMA foreign_keys = ON"
      exists "/root/dev/MyApp/script/../lib/MyApp/Model"
      exists "/root/dev/MyApp/script/../t"
     Dumping manual schema for MyApp::Schema to directory /root/dev/MyApp/script/../lib ...
@@ -1054,7 +1050,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 book"
+    $ 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
@@ -1085,7 +1081,7 @@ 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 DBIx::Class will look for our ResultSet Class:
 
-    mkdir lib/MyApp/Schema/ResultSet
+    $ mkdir lib/MyApp/Schema/ResultSet
 
 Then open C<lib/MyApp/Schema/ResultSet/Book.pm> and enter the following:
 
@@ -1104,7 +1100,7 @@ Then open C<lib/MyApp/Schema/ResultSet/Book.pm> and enter the following:
     sub created_after {
         my ($self, $datetime) = @_;
     
-        my $date_str = $self->_source_handle->schema->storage
+        my $date_str = $self->result_source->schema->storage
                               ->datetime_parser->format_datetime($datetime);
     
         return $self->search({
@@ -1114,15 +1110,6 @@ Then open C<lib/MyApp/Schema/ResultSet/Book.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/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::Book');
-
 Then add the following method to the C<lib/MyApp/Controller/Books.pm>:
 
     =head2 list_recent
@@ -1323,7 +1310,7 @@ URL:
 
 The "Author(s)" column will now contain both the first and last name.
 And, because the concatenation logic was encapsulated inside our
-Result Class, it keeps the code inside our .tt template nice and clean
+Result Class, it keeps the code inside our TT template nice and clean
 (remember, we want the templates to be as close to pure HTML markup as
 possible). Obviously, this capability becomes even more useful as you
 use to to remove even more complicated row-specific logic from your
@@ -1362,10 +1349,10 @@ clean this up.  First, let's add a method to our Book Result Class to
 return the number of authors for a book.  Open 
 C<lib/MyApp/Schema/Result/Book.pm> and add the following method:
 
-=head2 author_count
-
-Return the number of authors for the current book
-
+    =head2 author_count
+    
+    Return the number of authors for the current book
+    
     =cut
     
     sub author_count {
@@ -1429,6 +1416,10 @@ ways, it's an excellent to way accomplish this objective.  It will
 make your code cleaner, easier to write, less error-prone, and easier 
 to debug and maintain.
 
+Before you conclude this section, fire up the development server and
+hit Refresh in your browser... the output should be the same even
+though the backend code has been trimmed down.
+
 
 =head1 AUTHOR