[Bast-commits] r4456 - DBIx-Class/0.08/trunk/lib/DBIx/Class

castaway at dev.catalyst.perl.org castaway at dev.catalyst.perl.org
Mon Jun 2 19:46:12 BST 2008


Author: castaway
Date: 2008-06-02 19:46:12 +0100 (Mon, 02 Jun 2008)
New Revision: 4456

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship.pm
Log:
I suck, should read code while doccing it, not assume someone else got it right!


Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship.pm	2008-06-02 14:37:00 UTC (rev 4455)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship.pm	2008-06-02 18:46:12 UTC (rev 4456)
@@ -222,12 +222,13 @@
 
 =back
 
-Creates a one-to-many relationship, where the corresponding elements of the
-foreign class store the calling class's primary key in one (or more) of its
-columns. This relationship defaults to using C<$accessor_name> as the foreign
-key in C<$related_class> to resolve the join, unless C<$foreign_key_column>
-specifies the foreign key column in C<$related_class> or C<cond> specifies a
-reference to a join condition hash.
+Creates a one-to-many relationship, where the corresponding elements
+of the foreign class store the calling class's primary key in one (or
+more) of its columns. This relationship defaults to using the end of
+this classes namespace as the foreign key in C<$related_class> to
+resolve the join, unless C<$foreign_key_column> specifies the foreign
+key column in C<$related_class> or C<cond> specifies a reference to a
+join condition hash.
 
 =over
 
@@ -273,26 +274,28 @@
 =back
 
   # in an Author class (where Author has_many Books)
+  # assuming related class is storing our PK in "author_id"
   My::DBIC::Schema::Author->has_many(
     books => 
     'My::DBIC::Schema::Book', 
     'author_id'
   );
 
-  # OR (same result, assuming related_class is storing our PK)
+  # OR (same result)
   My::DBIC::Schema::Author->has_many(
     books => 
     'My::DBIC::Schema::Book', 
+    { 'foreign.author_id' => 'self.id' },
   );
-
-  # OR (same result)
+  
+  # OR (similar result, assuming related_class is storing our PK, in "author")
+  # (the "author" is guessed at from "Author" in the class namespace)
   My::DBIC::Schema::Author->has_many(
     books => 
     'My::DBIC::Schema::Book', 
-    { 'foreign.author_id' => 'self.id' },
   );
-  
 
+
   # Usage
   # resultset of Books belonging to author 
   my $booklist = $author->books;




More information about the Bast-commits mailing list