From: Arthur Axel 'fREW' Schmidt Date: Fri, 28 May 2010 04:27:52 +0000 (-0500) Subject: fill in example classes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=492be2ae9ef12d4c5be56f8f1d5aa49089105baa;p=dbsrgits%2Fdbix-class-introduction-presentation.git fill in example classes --- diff --git a/slideshow.html b/slideshow.html index f751727..18f214b 100644 --- a/slideshow.html +++ b/slideshow.html @@ -342,11 +342,54 @@ my @books = $book_model->search({
-
Example of a DBIC Result
+
package MyApp::Schema::Result::Author;
+use strict; use warnings;
+__PACKAGE__->table('authors');
+__PACKAGE__->add_columns(
+  id => {
+    data_type => 'int',
+    size      => 8,
+  },
+  title => {
+    data_type   => 'varchar',
+    is_nullable => 1,
+    size        => 255,
+  },
+);
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->has_many( books =>
+   'MyApp::Schema::Result::Book', 'author_id'
+);
+1;
+
-
Example of a DBIC Result
+
package MyApp::Schema::Result::Book;
+use strict; use warnings;
+__PACKAGE__->table('books');
+__PACKAGE__->add_columns(
+  id => {
+    data_type => 'int',
+    size      => 8,
+  },
+  name => {
+    data_type   => 'varchar',
+    is_nullable => 1,
+    size        => 255,
+  },
+  author_id => {
+    data_type   => 'int',
+    size        => 8,
+    is_nullable => 1, # <-- probably should be 0
+  },
+);
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->belongs_to( author =>
+   'MyApp::Schema::Result::Author', 'author_id'
+);
+1;
+