[Bast-commits] r9043 - DBIx-Class/0.08/trunk/maint

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Wed Mar 24 10:27:36 GMT 2010


Author: ribasushi
Date: 2010-03-24 10:27:36 +0000 (Wed, 24 Mar 2010)
New Revision: 9043

Modified:
   DBIx-Class/0.08/trunk/maint/joint_deps.pl
Log:
A better illustration how to add relationships at runtime

Modified: DBIx-Class/0.08/trunk/maint/joint_deps.pl
===================================================================
--- DBIx-Class/0.08/trunk/maint/joint_deps.pl	2010-03-24 09:54:03 UTC (rev 9042)
+++ DBIx-Class/0.08/trunk/maint/joint_deps.pl	2010-03-24 10:27:36 UTC (rev 9043)
@@ -19,17 +19,29 @@
 my $s = CPANDB::Schema->connect (sub { CPANDB->dbh } );
 
 # reference names are unstable - just create rels manually
-# is there a saner way to do that?
-my $distclass = $s->class('Distribution');
-$distclass->has_many (
+my $distrsrc = $s->source('Distribution');
+
+# the has_many helper is a class-only method (why?), thus
+# manual add_rel
+$distrsrc->add_relationship (
   'deps',
   $s->class('Dependency'),
-  'distribution',
+  { 'foreign.distribution' => 'self.' . ($distrsrc->primary_columns)[0] },
+  { accessor => 'multi', join_type => 'left' },
 );
-$s->unregister_source ('Distribution');
-$s->register_class ('Distribution', $distclass);
 
+# here is how one could use the helper currently:
+#
+#my $distresult = $s->class('Distribution');
+#$distresult->has_many (
+#  'deps',
+#  $s->class('Dependency'),
+#  'distribution',
+#);
+#$s->unregister_source ('Distribution');
+#$s->register_class ('Distribution', $distresult);
 
+
 # a proof of concept how to find out who uses us *AND* SQLT
 my $us_and_sqlt = $s->resultset('Distribution')->search (
   {




More information about the Bast-commits mailing list