From: Arthur Axel 'fREW' Schmidt Date: Fri, 28 May 2010 05:20:42 +0000 (-0500) Subject: singularize, less S::L, more win X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6548782ada04fcd087324240762a33445ca868cb;p=dbsrgits%2Fdbix-class-introduction-presentation.git singularize, less S::L, more win --- diff --git a/slideshow.html b/slideshow.html index 8ae42cb..d419494 100644 --- a/slideshow.html +++ b/slideshow.html @@ -598,47 +598,29 @@ sub new { 1;
-

relationships

+

Relationships

-

multiple authors

+

Multiple Authors

a few relationships

+ (really need picture here) (authors -- author_link_to_book -- books)
-

a few relationships

- ! -
- -
-

new join table

+

Join Table

CREATE TABLE author_and_books(
-  id      int(8)    primary key auto_increment,
-  book    int(8),
-  author  int(8),
-  foreign key (book)     references books(id),
-  foreign key (author)   references authors(id)
+  book_id    int(8),
+  author_id  int(8),
+  foreign key (book_id)     references books(id),
+  foreign key (author_id)   references authors(id)
 ) engine = InnoDB DEFAULT CHARSET=utf8;
 
-ALTER TABLE `books` DROP `author`
-
- -
-

new join table

-
CREATE TABLE author_and_books(
-  id      int(8)    primary key auto_increment,
-  book    int(8),
-  author  int(8),
-  foreign key (book)     references books(id),
-  foreign key (author)   references authors(id)
-) engine = InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE `books` DROP `author`
+ALTER TABLE `books` DROP `author`;
@@ -647,26 +629,11 @@ ALTER TABLE `books` DROP `author`

has_many

-
package Foo::Schema::Result::Books;
+
package Foo::Schema::Result::Book;
 
-__PACKAGE__->has_many( author_and_books => "Foo::Schema::Result::AuthorAndBooks",
-    { "foreign.book" => "self.id" },
+__PACKAGE__->has_many( author_and_books =>
+   'Foo::Schema::Result::Author_Book', 'book_id'
 );
-
-# This is auto generated by Schema::Loader
-
- -
-

has_many

-
package Foo::Schema::Result::Books;
-
-__PACKAGE__->has_many(
-author_and_books => # name of accessor
-"Foo::Schema::Result::AuthorAndBooks", # related class
-    { "foreign.book" => "self.id" } # Relationship (magic often works if not
-                                        # specified, but avoid!)
-);
-
@@ -675,12 +642,11 @@ author_and_books => # name of accessor

belongs_to

-
package Foo::Schema::Result::AuthorAndBooks;
+
package Foo::Schema::Result::Author_Book;
 
 __PACKAGE__->belongs_to(
-   book => # Accessor name
-   "Foo::Schema::Result::Books", # Related class
-   { id => "book" } # relationship
+   book =>
+   'Foo::Schema::Result::Book', 'book_id'
 );
 
@@ -690,10 +656,6 @@ __PACKAGE__->belongs_to(
-

with no coding...

-
- -

many_to_many

@@ -703,12 +665,11 @@ __PACKAGE__->belongs_to( use base 'DBIx::Class::Core'; __PACKAGE__->many_to_many( - authors => "author_and_books", 'author' + authors => 'author_and_books', 'author' ); 1; - - # This is NOT auto generated by Schema::Loader +
@@ -737,8 +698,7 @@ __PACKAGE__->many_to_many( ); 1; - -# This is NOT auto generated by Schema::Loader +